Nginx 空 Accept-Encoding 导致超时

问题描述 投票:0回答:1

当我想替换 Nginx 反向代理中的字符串时,我使用

sub_filter 'https://upstream.com' 'http://www.localhost:8080';
sub_filter_once off;

但是它不起作用(因为它被压缩了)所以我添加

proxy_set_header Accept-Encoding "";

但是随后请求超时(网关超时)。我想知道这是怎么可能的,我尝试使用邮递员将

Accept-Encoding
标头设置为空,并且工作正常,所以这是我这边的问题。

我的配置如下:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    server {
        listen       8080;
        server_name  localhost;

        location / {
            proxy_pass https://www.upstream.com;
            proxy_hide_header 'x-frame-options';
            proxy_cookie_domain ~^(.*)$ "http://www.localhost:8080";
            proxy_set_header X-Real-IP $remote_addr;
            proxy_cookie_path / "/; secure; HttpOnly; SameSite=none";
            sub_filter 'https://www.upstream.com' 'http://www.localhost:8080';
            sub_filter_once off;
            sub_filter_types text/html;
            proxy_set_header Accept-Encoding "";
        }
    }
}

PS:upstream.com只是一个例子,我使用另一个URL。

nginx compression reverse-proxy
1个回答
0
投票

尝试使用 gunzip 模块。更多信息这里

http {
    server {
        listen       8080;
        server_name  localhost;
        location / {
            proxy_pass https://www.upstream.com;
            proxy_hide_header 'x-frame-options';
            proxy_cookie_domain ~^(.*)$ "http://www.localhost:8080";
            proxy_set_header X-Real-IP $remote_addr;
            proxy_cookie_path / "/; secure; HttpOnly; SameSite=none";
            sub_filter 'https://www.upstream.com' 'http://www.localhost:8080';
            sub_filter_once off;
            sub_filter_types text/html;
            proxy_set_header Accept-Encoding "gzip";
            gunzip on;
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.