Centos7编译安装Nginx-1.16.0

前提:
我们准备一台新装的 CentOS7.6 服务器, 关闭 selinux, 清空 iptables 规则, 安装编译 nginx 依赖的软件包

一、yum remove -y firewalld–卸载防火墙

[root@centos7 ~]#iptables -vnL
Chain INPUT (policy ACCEPT 1400 packets, 1054K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 619 packets, 71030 bytes)
 pkts bytes target     prot opt in     out     source               destination 
[root@centos7 ~]#setenforce 0
setenforce: SELinux is disabled
[root@centos7 ~]#getenforce
Disabled

二、 安装epel源、wet命令

  yum install epel-release wget -y

三、安装依赖的包:

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 源码包, 解压编译安装:

 wget http://nginx.org/download/nginx-1.16.0.tar.gz

解压安装包

tar xf nginx-1.16.0.tar.gz 

切换到解压缩后的文件夹:

[root@centos7 nginx-1.16.0]#ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

自定义安装编译:可以通过./configure --help 查看帮助,完事进行安装

[root@centos7 nginx-1.16.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 --with-debug
make && make install

五、创建nginx账号,指定安装目录的所数组、所有者

[root@localhost nginx-1.16.0]# useradd nginx -s /sbin/nologin -r
[root@localhost nginx-1.16.0]# 
[root@localhost nginx-1.16.0]# chown nginx.nginx -R /apps/nginx/

六、编辑创建配置文件、设置开机启动

[root@centos7 nginx-1.16.0]#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
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# 
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# 
[root@localhost ~]# ss -ntl
State       Recv-Q Send-Q Local Address:Port                Peer Address:Port              
LISTEN      0      128                *:111                            *:*                  
LISTEN      0      128                *:80                             *:*                  
LISTEN      0      128                *:22                             *:*                  
LISTEN      0      100        127.0.0.1:25                             *:*                  
LISTEN      0      128               :::111                           :::*                  
LISTEN      0      128               :::22                            :::*                  
LISTEN      0      100              ::1:25                            :::*                  

七、测试访问
在这里插入图片描述

发布了24 篇原创文章 · 获赞 16 · 访问量 2112

猜你喜欢

转载自blog.csdn.net/weixin_42776624/article/details/103779489