nginx的http_sub_module / sub_filter和反向代理无法正常工作

时间:2015-08-08 12:38:11

标签: nginx proxy reverse inject

我正在尝试反向代理我的网站并修改内容。 为此,我使用sub_filter编译了nginx。 它现在接受sub_filter指令,但它不能以某种方式工作。

server {
    listen       8080;
    server_name  www.xxx.com;

    access_log  /var/log/nginx/www.goparts.access.log  main;
    error_log  /var/log/nginx/www.goparts.error.log;
    root   /usr/share/nginx/html;
    index  index.html index.htm;

    ## send request back to apache1 ##
    location / {
       sub_filter <title> '<title>test</title>';
 sub_filter_once on;


     proxy_pass  http://www.google.fr;
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
     proxy_redirect off;
     proxy_buffering off;
     proxy_set_header        Host            $host;
     proxy_set_header        X-Real-IP       $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

   }
}

请帮帮我

1 个答案:

答案 0 :(得分:24)

检查上游源是否已打开gzip,如果是,则需要

proxy_set_header Accept-Encoding "";

所以整个事情就像是

location / {
    proxy_set_header Accept-Encoding "";
    proxy_pass http://upstream.site/;
    sub_filter_types text/css;
    sub_filter_once off;
    sub_filter .upstream.site special.our.domain;
}

检查这些链接