nginx安装部署
1. 首先下载安装包(此次安装使用的是1.18版本)
nginx-1.18.0.tar.gz
2. 解压缩nginx
tar -zxvf nginx-1.18.0.tar.gz
3. 进入nginx-1.18目录进行编译
cd nginx-1.18
./configure
此时报错:./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=
(需要安装依赖的pcre、openssl、zlib库)
4. 安装pcre、openssl、zlib库(有yum的可以直接使用yum安装)
yum -y install pcre
yum -y install openssl
yum -y install zlib
(无法使用yum的情况,需要下载安装包)
pcre-8.44.tar.gz
tar zxvf pcre-8.44.tar.gz
tar zxvf openssl-1.1.1l.tar.gz
tar zxvf zlib-1.2.11.tar.gz
5. 编译nginx安装软件(制定安装目录和依赖包位置)
cd nginx-1.18
./configure --prefix=/nginx/nginx --with-openssl=/nginx/openssl-1.1.1l --with-pcre=/nginx/pcre-8.44 --with-zlib=/nginx/zlib-1.2.11
make && make install
*报错:configure: error: Invalid C++ compiler or C++ compiler flags
这是因为系统缺失 gcc-c++ 库,需要使用root安装gcc-c++环境:
yum -y install gcc-c++
yum install -y gcc
完成后再次执行make就可以了
6.启动nginx
cd /nginx/nginx/sbin
./nginx
报错:nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
以非root权限启动时,会出现 nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 错误,将 /usr/local/nginx/conf/nginx.conf 文件中的80端口改为1024以上(8080)
7. 测试nginx网页访问是否正常
curl http://ip:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>