yum -y install gcc gcc-c++ pcre pcre-devel gd-devel openssl openssl-devel zlib zlib-devel
id nginx || useradd nginx
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar xzf nginx-1.16.0.tar.gz
cd nginx-1.16.0/
#预编译
./configure \
--prefix=/usr/local/nginx \
--group=nginx \
--user=nginx \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
#编译安装
make && make install
#添加环境变量
cat >/etc/profile.d/nginx.sh<<EOF
export PATH=\${PATH}:/usr/local/nginx/sbin
EOF
#开机自启服务
cat >/usr/lib/systemd/system/nginx.service<<EOF
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
LimitNOFILE=51200
LimitNPROC=51200
LimitCORE=51200
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable nginx
#检测nginx配置文件
/usr/local/nginx/sbin/nginx -t
启动nginx服务
使用系统服务启动 systemctl start nginx 直接启动 /usr/local/nginx/sbin/nginx
nginx 命令功能
nginx -c /path/nginx.conf # 以特定目录下的配置文件启动nginx: nginx -s reload # 修改配置后重新加载生效 nginx -s stop # 快速停止nginx nginx -s quit # 正常停止nginx nginx -t # 测试当前配置文件是否正确 nginx -t -c /path/to/nginx.conf # 测试特定的nginx配置文件是否正确 #注意: nginx -s reload 命令加载修改后的配置文件