[root@centos8 ~]# yum -y install gcc pcre-devel openssl-devel zlib-devel wget make
[root@centos8 ~]# useradd -s /sbin/nologin nginx
[root@centos8 ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
[root@centos8 ~]# tar xf nginx-1.18.0.tar.gz
[root@centos8 ~]# cd nginx-1.18.0
[root@centos8 nginx-1.18.0]#./configure --prefix=/apps/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
[root@centos8 nginx-1.18.0]# make -j 4 && make install
[root@centos8 nginx-1.18.0]# ln -s /apps/nginx/sbin/nginx /usr/sbin/
[root@centos8 nginx-1.18.0]# nginx -v
nginx version: nginx/1.18.0
[root@centos8 nginx-1.18.0]# chown -R nginx.nginx /apps/nginx/
[root@centos8 nginx-1.18.0]# nginx
[root@centos7 ~]# curl -I 10.0.0.8
HTTP/1.1 200 OK
Server: nginx/1.18.0
[root@centos8 nginx-1.18.0]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@centos8 nginx-1.18.0]# nginx -s stop
[root@centos8 nginx-1.18.0]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@centos8 nginx-1.18.0]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/apps/nginx/run/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
#修改nginx配置文件中的pid
[root@centos8 nginx-1.18.0]# vim^Capps/nginx/conf/nginx.conf
pid /apps/nginx/run/nginx.pid;
[root@centos8 nginx-1.18.0]# mkdir /apps/nginx/run
[root@centos8 nginx-1.18.0]# chown -R nginx.nginx /apps/nginx/run
#重新加载service文件
[root@centos8 nginx-1.18.0]# systemctl daemon-reload
[root@centos8 nginx-1.18.0]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@centos8 nginx-1.18.0]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*