前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nginx | Nginx增加模块

Nginx | Nginx增加模块

作者头像
码农UP2U
发布2020-08-26 15:22:15
8950
发布2020-08-26 15:22:15
举报
文章被收录于专栏:码农UP2U码农UP2U

在上篇文章中安装 Nginx 时,因为我的系统中没有 zlib 库,因此无法直接编译 Nginx,需要忽略这个库。这个库的作用是让 Nginx 可以开启 gzip 来让 http 支持压缩功能。为了能够让我们的 Nginx 正常支持 gzip,我们需要安装 zlib 库,并且将忽略的库编译进来。具体步骤如下:

1、安装 zlib 库

安装 zlib 库,我们可以使用编译的方式,也可以使用 yum 进行安装,这里我们选择使用 yum 安装的方式。

代码语言:javascript
复制
[root@localhost ~]# yum install -y zlib-devel

2、查看 Nginx 的的编译参数

gzip 是 Nginx 默认支持的一个库,我们在上次安装时选择了忽略。如果是增加一个第三方库的话,在编译之前也需要查看上次的编译参数,因为在新编译时需要将上次的编译参数也增加进来,保证我们的编译只是在上次的基础上进行改动。而我们这里其实只需要将忽略 zlib 库的参数删除掉就可以了。

代码语言:javascript
复制
[root@localhost objs]# ./nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
configure arguments: --prefix=/usr/local/nginx --without-http_gzip_module

3、清除掉 objs 目录

代码语言:javascript
复制
[root@localhost nginx-1.18.0]# make clean
rm -rf Makefile objs
[root@localhost nginx-1.18.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

4、重新编译

把上次忽略的 zlib 的参数删除掉,就会将 gzip 编译到 Nginx 模块下。

代码语言:javascript
复制
[root@localhost nginx-1.18.0]# ./configure --prefix=/usr/local/nginx
[root@localhost nginx-1.18.0]# make

5、拷贝新 Nginx 文件

拷贝新 Nginx 文件前,需要停止掉 Nginx 的服务,然后将原来的 Nginx 文件进行备份,最后将新编译好的 Nginx 文件复制到原来 Nginx 的目录下。

代码语言:javascript
复制
[root@localhost nginx-1.18.0]# cd objs/
[root@localhost objs]# ls
autoconf.err  Makefile  nginx  nginx.8  ngx_auto_config.h  ngx_auto_headers.h  ngx_modules.c  ngx_modules.o  src
[root@localhost objs]# ./nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
configure arguments: --prefix=/usr/local/nginx
[root@localhost objs]# systemctl status nginx.service
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@localhost objs]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
[root@localhost objs]# ls /usr/local/nginx/sbin/
nginx.bak
[root@localhost objs]# cp ./nginx /usr/local/nginx/sbin/
[root@localhost objs]# ls /usr/local/nginx/sbin/
nginx  nginx.bak

6、启动服务

代码语言:javascript
复制
[root@localhost objs]# systemctl start nginx.service
[root@localhost objs]# systemctl status nginx.service
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since 六 2020-08-15 20:38:09 CST; 14s ago
  Process: 3956 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 3957 (nginx)
   CGroup: /system.slice/nginx.service
           ├─3957 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
           └─3958 nginx: worker process


8月 15 20:38:09 localhost.localdomain systemd[1]: Starting nginx...
8月 15 20:38:09 localhost.localdomain systemd[1]: Started nginx.
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-08-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码农UP2U 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档