1、安装依赖组件
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2、 下载安装包
wget https://nginx.org/download/nginx-1.16.0.tar.gz
3、编译安装
tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx
make && make install
4、启动nginx服务
cd /usr/local/nginx/sbin
./nginx
5、验证服务是否启动成功
[[email protected] sbin]# netstat -ntlp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 130245/nginx: master
6、添加nginx服务
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 -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target*
7、使用systemd管理
pkill nginx
systemctl start nginx
systemctl status nginx
原文地址:https://blog.51cto.com/11058442/2475823