在Centos7.2中,已经安装nginx的情况下,增加headers_more模块

1.首先查看自己之前安装的nginx的版本

## nginx -V

如下所示:

以上这张图最后一行有 --add-module=../headers-more-nginx-module这句话,是因为我安装成功之后截的图,安装模块之前是没有的.

2.下载nginx这个版本的tar包

当前我们的路径是~/application/nginx

下载 wget http://nginx.org/download/nginx-1.14.2.tar.gz
解压 tar zxvf nginx-1.14.2.tar.gz

3.去github下载headers-more-nginx-module

github地址 https://github.com/openresty/headers-more-nginx-module/

可以直接downloads,得到zip的包,
解压得到 headers-more-nginx-module文件夹

目前我们~/application/nginx/下就有了如下的文件

4.备份我们之前的nginx配置文件

演示备份到~/application/下
sudo cp /etc/nginx/nginx.conf ~/application/
sudo cp -r /etc/nginx/conf.d ~/application/

5.编译 安装

当前路径~/application/nginx

cd nginx-1.14.2

--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=../headers-more-nginx-module

上一步就是,把原来的配置参数全部复制过来,然后在尾部加上我们--add-module=../headers-more-nginx-module

然后执行

sudo make
sudo make install 

重启nginx
sudo systemctl restart nginx

另外,我看到别人说不要执行make install 的会覆盖之前的配置文件,但是我这样子操作了,之前的配置文件还是在的.不过还是提醒大家注意备份

看效果

在nginx的配置文件server中添加

more_clear_headers "Server";
more_set_headers "X-Author:bai";

再打开网页,就改变了

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值