NGINX1.16.1编译安装

OS version:Centos 7.6
官方下载地址http://nginx.org/

一、下载长期支持版1.16.1 并解压并安装安装常用的包。

 yum install  vim iotop bc gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl  openssl-devel zip unzip zlib-devel  net-tools lrzsz tree ntpdate telnet lsof tcpdump wget libevent libevent-devel \
bc  systemd-devel bash-completion traceroute -y
[root@aliyun7_v7 src]# pwd
/usr/local/src
[root@aliyun7_v7 src] tar  -xvf nginx-1.16.1.tar.gz
[root@aliyun7_v7 nginx-1.16.1]# pwd
/usr/local/src/nginx-1.16.1

二、执行编译安装

 [root@aliyun7_v7 nginx-1.16.1]./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@aliyun7_v7 nginx-1.16.1]# make
[root@aliyun7_v7 nginx-1.16.1]# make install

三、准备service启动脚本,可以根据需求过更改。

[root@s1 ~]# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target

四、启动nginx

systemctl daemon-reload
systemctl enable nginx
systemctl start nginx

启动测试:

[root@aliyun7_v7 sbin]# ss -ntl
State       Recv-Q Send-Q             Local Address:Port                            Peer Address:Port              
LISTEN      0      128                            *:8001                                       *:*                  
LISTEN      0      128                            *:7777                                       *:*                  
LISTEN      0      128                            *:111                                        *:*                  
LISTEN      0      128                            *:80                                         *:*                  
LISTEN      0      80                          [::]:3306                                    [::]:*

你可能感兴趣的:(计算机)