运行环境:Centos7
安装步骤:
一:安装依赖
yum install gcc pcre-devel openssl-devel zlib-devel -y
二:创建nginx用户
useradd -s /sbin/nologin nginx -M
三:下载nginx源码包
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar xf nginx-1.18.0.tar.gz
四:编译安装
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with stream_realip_module
make && make install
五:授权
chown -R nginx:nginx /usr/local/nginx
六:设置开机⾃启
cat > /lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx service
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
EOF
systemctl daemon-reload
systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to
/usr/lib/systemd/system/nginx.service.
systemctl start nginx