编译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编译配置
- ./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
最后的--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
- make && make install
5)在/etc/nginx/nginx.config中配置subs_filter
- 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://;
- }
- }
5)重启nginx服务
- systemctl restart nginx
搞定!
【参考资料】
CentOS - Installing nginx from source
Websites with Nginx on CentOS 5
编译nginx的源码安装subs_filter模块的更多相关文章
- Nginx unit 源码安装初体验
Nginx unit 源码安装初体验 上次介绍了从yum的安装方法(https://www.cnblogs.com/wang-li/p/9684040.html),这次将介绍源码安装,目前最新版为1. ...
- nginx 的源码安装
安装nginx之前要做的准备工作有:安装如下库 (1)gzip模块需要 zlib 库 (2)rewrite模块需要 pcre 库 (3)ssl 功能需要openssl库 还有一种简单的方法就是 yum ...
- linux应用之nginx的源码安装及配置(centos)
1.准备工作选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL.Nginx是C写的,需要用GCC编译:Nginx的 ...
- 关于nginx的源码安装方式
Nginx(engine x)是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器, 也是一个 IMAP/POP3/SMTP 代理服务器.在高连接并发的情况下, ...
- NFS, web,负载均衡,Nginx yum 源码安装
作业一:nginx服务1.二进制安装nginx 2.作为web服务修改配置文件 3.让配置生效,验证配置 [root@localhost ~]# systemctl stop firewalld.s ...
- zabbix,php,nginx,mysql源码安装 神仙操作
→软件包 mkdir /soft/ cd /soft ♦下载以下软件包 nginx-1.14.2.tar.gz wget http://nginx.org/download/nginx-1.14.2. ...
- linux nginx+php源码安装
PHP安装 1)下载 wget http://cn2.php.net/distributions/php-5.6.30.tar.gz 2)解压 tar –xf php-5.6.30 3)进入目录 cd ...
- CentOS源码安装Wireshark
(2019年2月19日注:这篇文章原先发在自己github那边的博客,时间是2016年8月25日) Wireshark为网络管理员常用的一个网络管理工具,通过使用这个软件,我们可以对本机网卡上的经过的 ...
- 源码安装Nginx加TCP反向代理模块
说明: 安装方式是源码编译安装,因此先安装相关依赖,否则报错. yum -y install gcc* patch openssl openssl-devel 安装步骤: 下载nginx源码包: wg ...
随机推荐
- 块级格式化上下文(block formatting context)、浮动和绝对定位的工作原理详解
CSS的可视化格式模型中具有一个非常重要地位的概念——定位方案.定位方案用以控制元素的布局,在CSS2.1中,有三种定位方案——普通流.浮动和绝对定位: 普通流:元素按照先后位置自上而下布局,inli ...
- 25、继续echarts实现中国地图
1. 以上是实现的效果 下边是实现的代码,上一篇地图没有颜色,是因为没有引入zrender包,因为echarts画地图是基于zrender实现的 <!DOCTYPE html> <h ...
- JQuery之正则表达式
1.定义正则表达式 /.../ 用于定义正则表达式 /.../g 表示全局匹配 /.../i 表示不区分大小写 /.../m 表示多行匹配 2.匹配正则表达式 非全局模式,不分组 var patte ...
- asp.net C# 未能加载文件或程序集或它的某一个依赖项。需要强名称程序集。的解决办法
asp.net C# 未能加载文件或程序集或它的某一个依赖项.需要强名称程序集.的解决办法 出现这个错误是原因:是有签名的DLL引用了无签名的DLL 如上图所示,就是因为引用Entity.MVCEnt ...
- 终极优化_详解Win7旗舰版系统中可以关闭的服务
Win7旗舰版系统是一款功能强大的系统,不过对于很多用户很多功能却使用不上,而支持功能的很多服务也多少占用了系统资源,那么我们可以通过关闭一些不使用的服务来达到让win7系统运行速度加快的目的.下面小 ...
- 【Django】Django model与数据库操作对应关系(转)
Django对数据库的操作分用到三个类:Manager.QuerySet.Model. Manager的主要功能定义表级方法(表级方法就是影响一条或多条记录的方法),我们可以以models.Manag ...
- bs4的学习
soup = BeautifulSoup(html,'html.parser') #'html.parser'是html解析器必须有soup.find_all("a") #等价于 ...
- afterTextChanged() callback being called without the text being actually changed
afterTextChanged() callback being called without the text being actually changed up vote8down votefa ...
- WordPress建站指南
WordPress建站指南(1) 写在前面: 3月份用10天零碎时间火速完成了建站,后台95%的工作都交给了WP(WordPress).如果想偷懒的话,WP是一个绝好的选择,估计有个小半天就建完收 ...
- Dijkstra 最短路算法(只能计算出一条最短路径,所有路径用dfs)
上周我们介绍了神奇的只有五行的 Floyd 最短路算法,它可以方便的求得任意两点的最短路径,这称为"多源最短路".本周来来介绍指定一个点(源点)到其余各个顶点的最短路径,也叫做&q ...