1. yum install -y gcc-c++
2. yum install -y pcre pcre-devel
3. yum install -y zlib zlib-devel
4. yum install -y openssl openssl-devel
1. wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
2. tar -zxvf nginx-1.12.0.tar.gz
1. cd nginx-1.12.0
2. ./configure # 或自定义安装配置
3. make
4. make install
默认安装在 /usr/local/nginx 下
1. cd /usr/local/nginx/sbin
2. ./nginx # 启动
3. ./nginx -s quit
./nginx -s stop # 停止
4. ./nginx -s reload # 重新加载(修改配置文件后可以用来应用新配置)
./nginx -s quit: 此方式停止步骤是待 nginx 进程处理任务完毕进行停止。
./nginx -s stop: 此方式相当于先查出 nginx 进程id再使用 kill 命令强制杀掉进程。
检查 nginx 占用的进程与端口
1. ps aux | grep nginx
2. netstat -antp | grep nginx
1. vim /usr/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 -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
注意:[Service] 的启动、重启、停止命令全部要求使用绝对路径
[Install] 运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
1. systemctl enable nginx # 配置开机启动
2. systemctl status nginx # 查看 nginx 状态
杀死 nginx 重启 nginx
1. pkill -9 nginx
2. ps aux | grep nginx
3. systemctl start nginx
重启服务器,检查状态
4. systemctl status nginx
原文:https://www.cnblogs.com/cybertime/p/13908192.html