nginx - nginx 的 http_sub_module/sub_filter 和反向代理不起作用

标签 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;

   }
}

请帮助我

最佳答案

检查上游源是否开启了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;
}

检查这些链接

关于nginx - nginx 的 http_sub_module/sub_filter 和反向代理不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31893211/

相关文章:

ssl - 服务器在使用 https [nginx] 时显示 404

ruby-on-rails - 发生未处理的低级错误。应用程序日志可能包含详细信息

google-chrome - 如何在不触发浏览器 SSL 检查的情况下重定向 www 流量?

ssl - Mumble 的 NGINX 子域和 proxy_pass

javascript - 如何在 JavaScript 中就地反转字符串?

algorithm - Reverse LinkedList - 链表工具

python - 使用 Nginx+uWsgi+Web.py 的 HTTP 响应中缺少 header

proxy - TOR 作为 HTTP 代理而不是 SOCKS

node.js - Express - req.ip 返回 127.0.0.1

javascript - 反转数组时有 2 个不同的输出