编译安装nginx1.16.0


一、编译安装nginx

1、系统环境

[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、安装依赖

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

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
echo $?

4、添加环境变量

[root@ansible-server sbin]# vi /etc/profile
export PATH="/usr/local/nginx/sbin"

#使环境变量生效
[root@ansible-server sbin]# source /etc/profile

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

[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、配置启动服务

[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
#备注:改成自己nginx的安装路径

#重载并启动服务

[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.

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM