我使用centos7X64最小化安装 CentOS-7-x86_64-Minimal-1708
关闭防火墙和加入放行端口二选一
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)[root@localhost ~]# firewall-cmd --state
not running
[root@localhost ~]#firewall-cmd --zone=public --add-port=80/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)firewall-cmd --reload #刷新防火墙 使其生效firewall-cmd --zone=public --list-ports #查看防火墙放行端口列表[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
success
[root@localhost ~]# firewall-cmd --reload #刷新防火墙 使其生效
success
[root@localhost ~]# firewall-cmd --zone=public --list-ports #查看防火墙放行端口列表
80/tcp
[root@localhost ~]#yum -y install wgetyum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel官方查看最新稳定版本 nginx1.12.2官网链接直达 我现在最新稳定版本是:nginx-1.12.2
wget -c https://nginx.org/download/nginx-1.12.2.tar.gztar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2./configuremake
make installcd /usr/local/nginx/sbin/
./nginx
./nginx -s reload #重新加载配置文件
./nginx -s quit #:推荐 待nginx进程处理任务完毕进行停止
./nginx -s stop #:先查出nginx进程id再使用kill命令强制杀掉进程。ps aux|grep nginx在rc.local增加启动代码就可以了。
vi /etc/rc.local底部增加一行:
/usr/local/nginx/sbin/nginx设置执行权限:
chmod 755 /etc/rc.local