全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 15316|回复: 7

求教nginx反代替换

[复制链接]
发表于 2017-4-13 16:51:40 | 显示全部楼层 |阅读模式
100金钱
本帖最后由 gaoji.me 于 2017-4-13 17:12 编辑

使用sub_filter:

试验了好多次一直未成功。

  1. server    {
  2.         listen          80;
  3.         server_name     t.abc.com;

  4.         location / {
  5.                 proxy_pass              http://abc.com/;
  6.                 proxy_redirect          off;
  7.                 proxy_set_header        X-Real-IP       $remote_addr;
  8.                 proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;


  9.                 sub_filter  'abc' 't.abc';
  10.                 sub_filter_types *;
  11.                 sub_filter_once off;

  12.         }
  13.     }
复制代码


想用 t.abc.com 反代 abc.com

替换其中所有的abc.comt.abc.com

但是一直不成功

Nginx 的模块

  1. nginx -V
  2. nginx version: nginx/1.4.6 (Ubuntu)
  3. built by gcc 4.8.2 (Ubuntu 4.8.2-16ubuntu6)
  4. TLS SNI support enabled
  5. configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module
复制代码


====================

解决后的代码:

  1. server    {
  2.         listen          80;
  3.         server_name     t.abc.com;
  4.         location / {
  5.                 proxy_set_header Accept-Encoding "";
  6.                 proxy_pass             http://abc.com/;
  7.                 proxy_redirect          off;
  8.                 proxy_set_header        X-Real-IP       $remote_addr;
  9.                 proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  10.                 sub_filter  'abc' 't.abc';
  11.                 sub_filter_types *;
  12.                 sub_filter_once off;

  13.         }
  14.     }
复制代码




最佳答案

查看完整内容

proxy_set_header Accept-Encoding ""; 把这个加在proxy_pass的上一行重启nginx或者重新加载配置文件
发表于 2017-4-13 16:51:41 | 显示全部楼层
proxy_set_header Accept-Encoding "";
把这个加在proxy_pass的上一行重启nginx或者重新加载配置文件
发表于 2017-4-13 16:58:40 | 显示全部楼层
http://w4.pw/jyHpo
发表于 2017-4-13 17:01:33 | 显示全部楼层
我会,但你至少告诉我反代哪个站
发表于 2017-4-13 17:06:34 | 显示全部楼层
把反代后的站发出来给你参谋下
 楼主| 发表于 2017-4-13 17:09:47 | 显示全部楼层
今晚我是你的 发表于 2017-4-13 16:51
proxy_set_header Accept-Encoding "";
把这个加在proxy_pass的上一行重启nginx或者重新加载配置文件 ...



已经解决
发表于 2017-4-13 17:10:07 | 显示全部楼层
趁机学习一把了
发表于 2017-4-14 14:53:43 | 显示全部楼层
要把上游的压缩给关掉
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-9-24 22:26 , Processed in 0.059912 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表