centos7.5 编译安装nginx1.16

官方源码包下载地址:
https://nginx.org/en/download.html

1.登录官网获取下载链接直接wget

[root@localhost ~]# wget https://nginx.org/download/nginx-1.16.0.tar.gz

2.解压文件

[root@localhost ~]# tar -xf nginx-1.16.0.tar.gz

3.检查当前环境是否符合编译要求,并生成makefile文件

[root@localhost ~]# cd nginx-1.16.0
[root@localhost 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

4.根据makefile文件内容生成指定的模块

[root@localhost nginx-1.16.0]# make

5.将生成的模块复制到相应的目录,如果目录不存在会创建目录 创建用户

[root@localhost nginx-1.16.0]# make install 
[root@localhost nginx-1.16.0]# useradd nginx -s /sbin/nologin -u 2000
[root@localhost nginx-1.16.0]# chown nginx.nginx -R /apps/nginx/
[root@localhost nginx-1.16.0]# /apps/nginx/sbin/nginx -V    //可查看版本

6.创建服务脚本


[root@localhost nginx-1.14.2]# vim /usr/lib/systemd/system/nginx.service

[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid                   #此项为进程的编号,可以在nginx的配置文件中查询的相应的位置
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf         #编译安装时nginx二进制程序所在的位置以及配置文件所在的位置
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

7.将执行文件关联到sbin下

[root@localhost ~]# ln -s /apps/nginx/sbin/nginx /sbin/nginx

8.测试服务脚本是否能启动

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
#已经能够正常使用
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值