Centos 7 安装nginx指定版本
官方版本列表: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
可选 --with-stream
nginx-rtmp-module模块参考:Centos7 搭建Nginx+rtmp+hls直播推流服务器 - 冬音 - 博客园 (cnblogs.com)
*./configure: error: the HTTP rewrite module requires the PCRE library 解决方案
yum -y install pcre-devel
#debian
apt-get install libpcre3 libpcre3-dev
*./configure: error: SSL modules require the OpenSSL library. 解决方案
yum -y install openssl openssl-devel
#debian
sudo apt-get install libssl-dev
sudo apt-get install libssl0.9.8
* ./configure: error: C compiler cc is not found 解决方案
yum -y install gcc gcc-c++ autoconf automake make
#debian安装方法
apt-get install linux-headers-$(uname -r | sed 's,[^-]*-[^-]*-,,')
apt-get install build-essential
* make: *** No rule to make target `build', needed by `default'. Stop. 解决方案:
* zlib library
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
#debian https://blog.csdn.net/one312/article/details/104087364
apt-get install zlib1g
apt-get install zlib1g.dev
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