X-Accel 的 Nginx 代理将方法更改为 GET

X-Accel 的 Nginx 代理将方法更改为 GET

我一直在开发中运行 Nginx X-Accel 代理,其配置如下:

upstream gate_proxy {
    server 127.0.0.1:8889;
}

server {
    listen      80 default_server;
    server_name default;
    charset     utf-8;
    client_max_body_size 75M;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Send all traffic to gate first
    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://gate_proxy;
    }

    # Proxy to Apache after X-Accel
    location /x-accel-apache/ {
        internal;
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;

        # Make sure the trailing slash is maintained here, as this affects the URI relayed.
        proxy_pass http://127.0.0.1:8081/;
    }
}

一切运行正常,直到我接近生产时才意识到我的 Nginx 是 1.4.6 并且已经非常过时,并试图确保我拥有最新的更新等。

现在 1.10.1 不再起作用,所有 POST 请求都会在前端的 Nginx 中接收,但当它们最终被代理到http://127.0.0.1:8081/它们以 GET 方法接收。

编辑:另外,确认 gate_proxy (http://127.0.0.1:8889) 在更新后仍能接收 POST 方法。

答案1

解决https://stackoverflow.com/a/41282238/698289

在我自己的配置中,该location /x-accel-apache/部分现在看起来像:

# Proxy to Apache after X-Accel
location @webapp {        
    internal;
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Scheme $scheme;

    set                     $stored_redirect_location $upstream_http_x_accel_redirect_location;
    proxy_pass              http://127.0.0.1:8081$stored_redirect_location;
}

在 gate_proxy 中我设置了以下内容:

set_header('X-Accel-Redirect', '@webapp') set_header('X-Accel-Redirect-Location', request_path)

确认可与当前最新稳定版本(1.10.3)和主线版本(1.11.9)兼容

相关内容