Centos 7 安装nginx指定版本

时间:2022-06-16 18:45:55

官方版本列表:http://nginx.org/download/

1.安装

wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar -zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure
make && make install

编译时添加模块

./configure --with-http_stub_status_module --with-http_ssl_module

*./configure: error: the HTTP rewrite module requires the PCRE library 解决方案

yum -y install pcre-devel

*./configure: error: SSL modules require the OpenSSL library. 解决方案

yum -y install openssl openssl-devel

* ./configure: error: C compiler cc is not found 解决方案

yum -y install gcc gcc-c++ autoconf automake make

* make: *** No rule to make target `build', needed by `default'.  Stop. 解决方案:

yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel

2.配置

* 配置文件路径(可能不一样)/usr/local/nginx/conf/nginx.conf

#配置服务
vi /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target [Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true [Install]
WantedBy=multi-user.target
#创建服务
systemctl enable nginx.service
#常用命令
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #结束nginx
systemctl restart nginx.service #重启nginx

3.防火墙配置

端口放行:

firewall-cmd --zone=public --list-ports  #查询放行的端口
firewall-cmd --zone=public --add-port=80/tcp --permanent #新增放行端口(80端口)
firewall-cmd --reload #一定要重启防火墙

或者直接关闭防火墙:

systemctl stop firewalld.service
systemctl disable firewalld.service

附:

配置文件编辑

vi /usr/local/nginx/conf/nginx.conf 

https://blog.csdn.net/testcs_dn/article/details/51461750

https://www.cnblogs.com/karrya/p/11851496.html

https://www.cnblogs.com/czlun/articles/7010601.html

https://blog.csdn.net/testcs_dn/article/details/51461999

https://www.cnblogs.com/yan-zm/p/12217118.html