一、yum安装和配置nginx
1、查看环境
cat /etc/redhat-release
2、添加yum源
sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
3、安装
sudo yum install nginx
4、配置nginx服务
#开机启动 sudo systemctl enable nginx #启动服务 sudo systemctl start nginx #停止服务 sudo systemctl restart nginx #重新加载 sudo systemctl reload nginx
5、打开防火墙端口
$ sudo firewall-cmd --zone=public --permanent --add-service=http success $ sudo firewall-cmd --reload success 查看防火墙服务 $ sudo firewall-cmd --list-service ssh dhcpv6-client http
二、编译安装
1、wget或者官网下载(https://nginx.org/en/download.html)
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
2、解压
tar -zxvf nginx-1.12.0.tar.gz cd nginx-1.12.0
3、配置
./configure --prefix=/home/web/nginx
4、编译安装
make make install
5、启动、停止nginx
cd /home/web/nginx/sbin/ #状态 ps -ef | grep nginx #强制停止 pkill -9 nginx #检查配置文件是否正确 ./nginx -t #停止 ./nginx -s stop ./nginx -s quit #启动 ./nginx #重新加载配置文件 ./nginx -s reload
6、开机自启动
vi /etc/rc.local /*** touch /var/lock/subsys/local /home/web/nginx/sbin/nginx ***/ chmod 755 rc.local