编译nginx的源码安装subs

2022年 10月 18日 发表评论
腾讯云正在大促:点击直达 阿里云超级红包:点击领取
免费/便宜/高性价比服务器汇总入口(已更新):点击这里了解

本站教程收集整理的这篇文章主要介绍了编译nginx的源码安装subs_filter模块,本站教程本站觉得挺不错的,现在分享给大家,也给大家做个参考。

使用Nginx的反向代理功能搭建nuget镜像服务器时,需要针对官方nuget服务器的响应内容进行字符串替换,比如将www.nuget.org替换为镜像服务器的主机名,将https://替换为http://。而Nginx没有内置这个功能,需要使用第三方module,比如subs_filter。

在Nginx中配置module,不像apache那么简单(复制module文件,修改配置文件),需要将module的源码引入Nginx的源码,自己编译Nginx并安装。

下面分享一下自己在centos上编译并安装包含subs_filter模块的Nginx的实际操作步骤。

0)如果centos上没有安装Nginx,先用yum安装一下,yum安装时会自动添加一些Nginx的初始配置文件,比如/etc/rc.d/init.d/Nginx,/etc/Nginx/Nginx.conf(自己编译安装时不会添加这些配置文件)。

yum install Nginx

1)从http://wiki.nginx.org/Install的 #source Releases 部分得到Nginx的源码下载地址,下载解压。

wget http://Nginx.org/download/Nginx-1.8.0.tar.gz   tar xf Nginx-1.8.0.tar.gz

2)git签出subs_filter的源码(参考nginx_substitutions_filter)。

git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git

(注:保存路径为/git/ngx_http_substitutions_filter_module)

3)Nginx编译配置

编译nginx的源码安装subs

./configure --prefix=/usr/share/Nginx --sbin-path=/usr/sbin/Nginx --conf-path=/etc/Nginx/Nginx.conf --error-log-path=/var/log/Nginx/error.log --http-log-path=/var/log/Nginx/access.log --http-client-body-temp-path=/var/lib/Nginx/tmp/clienT_Body --http-proxy-temp-path=/var/lib/Nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/Nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/Nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/Nginx/tmp/scgi --pid-path=/run/Nginx.pid --lock-path=/run/lock/subsys/Nginx --user=Nginx --group=Nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module  --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --add-module=/git/ngx_http_substitutions_filter_module@H_673_29@

编译nginx的源码安装subs

最后的--add-module就是引入的subs_filter模块。

注:如果出现下面的错误

./configure: error: the http rewrite module requires the PCRE library.  You can either disable the module by using --without-http_rewrite_module  option, or install the PCRE library into the system, or build the PCRE library  statically from the source with Nginx by using --with-pcre=<path> option.

需要安装 libpcre3

apt-get install libpcre3 libpcre3-dev

4)编译并安装Nginx

@H_594_8@make && make install

5)在/etc/Nginx/Nginx.config中配置subs_filter

编译nginx的源码安装subs

server {      listen       80;      listen       [::]:80;      server_name  [mirror_host_name];        LOCATIOn / {          proxy_pass http://www.nuget.org;          proxy_cache nuget-cache;          proxy_cache_valid 168h;          proxy_ignore_headers Set-Cookie Cache-Control;          subs_filter www.nuget.org [mirror_host_name];          subs_filter https:// http://;@H_673_29@      }  }

编译nginx的源码安装subs

5)重启Nginx服务

systemctl restart Nginx

搞定!

【参考资料】

CentOS - Installing nginx from source

Websites with Nginx on CentOS 5

本站总结

以上是本站教程为你收集整理的编译nginx的源码安装subs_filter模块全部内容,希望文章能够帮你解决编译nginx的源码安装subs_filter模块所遇到的程序开发问题。

如果觉得本站教程网站内容还不错,欢迎将本站教程推荐给好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。

小咸鱼

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: