编译安装nginx

编译安装nginx1.16.0

一、编译安装nginx

1、系统环境

1
2
3
4
[root@ansible-server ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@ansible-server ~]# uname -r
3.10.0-862.el7.x86_64

2、安装依赖

1
2
yum install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
useradd nginx -s /sbin/nologin -M

3、安装nginx1.16.0

1
2
3
4
5
6
7
8
mkdir -p /nulige/tools
cd /nulige/tools
wget https://nginx.org/download/nginx-1.16.0.tar.gz
tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
make && make install

4、添加环境变量

1
2
3
4
[root@ansible-server sbin]# vi /etc/profile
export PATH="/usr/local/nginx/sbin"
#使环境变量生效
[root@ansible-server sbin]# source /etc/profile

5、查看版本,可以看到编译的模块

1
2
3
4
5
6
[root@ansible-server sbin]# nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module

6、配置启动服务

1
2
3
4
5
6
7
8
9
[root@ansible-server conf]# vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#重载并启动服务
[root@ansible-server conf]# systemctl daemon-reload
[root@ansible-server conf]# systemctl start nginx
[root@ansible-server conf]# systemctl enable nginx
[root@ansible-server conf]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; static; vendor preset: disabled)
Active: active (running) since Sat 2019-05-18 16:36:48 CST; 11s ago
Main PID: 26928 (nginx)
CGroup: /system.slice/nginx.service
├─26928 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
└─26929 nginx: worker process

May 18 16:36:48 ansible-server systemd[1]: Starting nginx - high performance web server...
May 18 16:36:48 ansible-server systemd[1]: Started nginx - high performance web server.