Nginx 编译安装-1.61.1

Posted yinx1n

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx 编译安装-1.61.1相关的知识,希望对你有一定的参考价值。

准备编译安装基础环境

[root@node1 ~]# yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed

 

解压缩 nginx 包

[root@node1 ~]# tar xf nginx-1.16.1.tar.gz

 

编译安装

[root@node1 ~]# cd nginx-1.16.1/

[root@node1 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 --with-debug

[root@node1 nginx-1.16.1]# make && make install

 

创建 nginx 系统账户

[root@node1 ~]# useradd nginx -s /sbin/nologin

 

更改 nginx 安装目录所属主和所属组为 nginx

[root@node1 ~]# chown nginx.nginx -R /apps/nginx

 

编写 nginx 自启动脚本

[root@node1 ~]# vim /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=/apps/nginx/logs/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 /apps/nginx/logs/nginx.pid
ExecStartPre=/apps/nginx/sbin/nginx -t
ExecStart=/apps/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

启动 nginx,并设为开机自启

[root@node1 ~]# systemctl daemon-reload

[root@node1 ~]# systemctl start nginx

[root@node1 ~]# ss -ntl
State     Recv-Q   Send-Q   Local Address:Port   Peer Address:Port
LISTEN   0       100     127.0.0.1:25       *:*
LISTEN   0       128     *:111           *:*
LISTEN   0         128     *:80             *:*
LISTEN   0       128     *:22            *:*
LISTEN   0       100     [::1]:25          [::]:*
LISTEN   0       128     [::]:111           [::]:*
LISTEN   0       128     [::]:22            [::]:*

 

[root@node9 ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

以上是关于Nginx 编译安装-1.61.1的主要内容,如果未能解决你的问题,请参考以下文章

nginx 编译安装详解

怎么编译安装nginx1.8.1

Nginx编译安装及编译参数讲解

nginx编译安装服务启动脚本在哪

安装nginx的时候,是怎么编译老出错啊

编译安装——什么是开放源代码编译器与可执行文件——编译安装nginx