tar –zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure --prefix=/usr/local/nginx
若提示没有C编译环境,由于新安装的Centos7没有安装编译C的环境,需要先进行编译环境安装。
yum install gcc gcc-c++ kernel-devel
./configure --prefix=/usr/local/nginx--with-http_ssl_module
此时若提示error: the HTTP rewrite module requires the PCRE library.
安装yum -y install pcre-devel
./configure --prefix=/usr/local/nginx
此时若提示error: the HTTP gzip module requires the zlib library.
安装yum install -y zlib-devel
./configure --prefix=/usr/local/nginx--with-http_ssl_module
make (如果需要支持ipv6增加--with-ipv6编译出现警告错误在上面加上--with-cc-opt="-Wno-error")
如果提示SSL modules require the OpenSSL library.
yum -y install openssl openssl-devel
make install
编辑 vi nginx.conf 修改相关代理配置
之后保存配置变更:./nginx –s reload
如果报如果报nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed,执行:
./nginx -c /usr/local/nginx/conf/nginx.conf
修改完成配置,配置防火墙允许80端口访问。
systemctl start firewalld
firewall-cmd --zone=public --add-port=80/tcp --permanent
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp –permanent
配置systemd:
vim /usr/lib/systemd/system/nginx.service:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
开机自启动:
systemctl daemon-reload
systemctl enable nginx