Nginx编译安装过程

本文档详细介绍了在CentOS7系统上安装Nginx 1.16.0的步骤,包括解压软件包、安装依赖、创建用户、配置编译选项、软件编译与安装、创建软链接以及启动和检查Nginx服务。特别强调了在配置阶段添加必要的模块以避免配置错误。
摘要由CSDN通过智能技术生成

系统环境

[root@web01 tools]# uname -r
3.10.0-862.el7.x86_64
[root@web01 tools]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 

部署安装

1)解压软件包

[root@web01 tools]# pwd
/server/tools
[root@web01 tools]# ll
-rw-r--r-- 1 root  root  1032345 Jul 10  2021 nginx-1.16.0.tar.gz
[root@web01 tools]# tar xf nginx-1.16.0.tar.gz 
[root@web01 tools]# ll
total 1012
drwxr-xr-x 9 nginx nginx     186 Jun 26 19:49 nginx-1.16.0
-rw-r--r-- 1 root  root  1032345 Jul 10  2021 nginx-1.16.0.tar.gz

2)安装依赖软件包

yum install -y openssl-devel pcre-devel openssl

3)创建用户

useradd nginx -M -s /sbin/nologin

4)配置

[root@web01 nginx-1.16.0]# ./configure --user=nginx --group=nginx --prefix=/app/nginx-1.16.0

此处如果需要进行其他配置,可参考官方文档进行添加。
经过实践后发现,配置相关参数时缺少模块,因此完整的配置过程应该是下面的。

[root@web01 nginx-1.16.0]# ./configure --user=nginx --group=nginx --prefix=/app/nginx-1.16.0 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_slice_module

具体错误现象可以查看相关文章:
nginx: [emerg] unknown directive “stub_status“ in /app/nginx/conf/conf.d/state.conf:7

5)软件编译

[root@web01 nginx-1.16.0]# make && make install

ps.此处的(4)(5)必须连续进行,中间不得有别的命令

6)创建软链接

生产环境经验
[root@web01 nginx-1.16.0]# ln -s /app/nginx-1.16.0 /app/nginx
[root@web01 app]# cd /app/
[root@web01 app]# ll
total 0
lrwxrwxrwx 1 root root 17 Jun 26 20:48 nginx -> /app/nginx-1.16.0
drwxr-xr-x 6 root root 54 Jun 26 20:39 nginx-1.16.0

内部运维人员可以在 /app/nginx 目录下操作,一方面是便于查看不同nginx版本号,另一方面则在nginx需要更新时,可以删除原本旧的软链接,创建新版本的 /app/nginx 软链接。

7)检查nginx配置文件语法,并启动nginx服务

检查语法格式,正确
[root@web01 tools]# /app/nginx/sbin/nginx -t
nginx: the configuration file /app/nginx-1.16.0/conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx-1.16.0/conf/nginx.conf test is successful

用绝对路径方式启动
[root@web01 tools]# /app/nginx/sbin/nginx

检查端口号,正常启动
[root@web01 tools]# netstat -lntup|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      10864/nginx: master 

另外检查nginx启动成功的方法,以本文主机为例

[root@web01 tools]# hostname -I
10.0.0.7 172.16.1.7 
[root@web01 tools]# curl -I 10.0.0.7
HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Sun, 26 Jun 2022 12:58:12 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 26 Jun 2022 12:39:30 GMT
Connection: keep-alive
ETag: "62b85382-264"
Accept-Ranges: bytes

或者打开本机的浏览器,输入10.0.0.7:80

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值