全球主机交流论坛

标题: 求教nginx反代替换 [打印本页]

作者: gaoji.me    时间: 2017-4-13 16:51
标题: 求教nginx反代替换
本帖最后由 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.     }
复制代码





作者: 今晚我是你的    时间: 2017-4-13 16:51
proxy_set_header Accept-Encoding "";
把这个加在proxy_pass的上一行重启nginx或者重新加载配置文件
作者: 月の天使    时间: 2017-4-13 16:58
http://w4.pw/jyHpo
作者: 今晚我是你的    时间: 2017-4-13 17:01
我会,但你至少告诉我反代哪个站
作者: cgs3238    时间: 2017-4-13 17:06
把反代后的站发出来给你参谋下
作者: gaoji.me    时间: 2017-4-13 17:09
今晚我是你的 发表于 2017-4-13 16:51
proxy_set_header Accept-Encoding "";
把这个加在proxy_pass的上一行重启nginx或者重新加载配置文件 ...



已经解决
作者: cgs3238    时间: 2017-4-13 17:10
趁机学习一把了
作者: linkec    时间: 2017-4-14 14:53
要把上游的压缩给关掉




欢迎光临 全球主机交流论坛 (https://sunk.eu.org/) Powered by Discuz! X3.4