1,安装必须环境
nginx的编译需要c++,同时pcre(重定向支持)和openssl(https支持)也需要安装。
yum install gcc-c++
yum -y install pcre*
yum -y install openssl*
2,官网下载http://nginx.org/en/download.html
使用wget下载(地址也是从上面的官网页面上复制)
wget http://nginx.org/download/nginx-1.12.2.tar.gz
cd /usr/local/ #下载到这里
tar -zxvf nginx-1.12.2.tar.gz #解压
rm -rf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure #进行初始化配置
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make install #进行编译,编译完成后会发生成了/usr/local/nginx/目录
cd /usr/local/nginx/sbin
./nginx #启动nginx
curl http://localhost #验证是否成功
配置文件在:
/usr/local/nginx/conf/nginx.conf
其他:
./nginx -s stop #停止
./nginx -s reload #重启
可能80端口没有开放:
netstat -ntlp #列出所有端口
/sbin/iptables -I INPUT -p tcp --dport 20880 -j ACCEPT #写入修改
/etc/init.d/iptables save #保存修改
service iptables restart #重启防火墙,修改生效