【问题标题】:nginx post method does not worknginx post方法不起作用
【发布时间】:2019-01-07 20:07:06
【问题描述】:

我在 nginx 使用 Http POST 方法下载 excel 文件时遇到问题。事实上,我得到了一个状态码:405 Not Allowed。

这是我的配置

upstream backend{
    server localhost:9090;
    server localhost:9091;
    server localhost:9092;
    server localhost:9093;
}

server {
    listen       8887;
    server_name  localhost;

    location / {
        proxy_pass  http://backend;
        proxy_next_upstream error timeout http_404; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
    }
}

我该如何解决这个问题。

提前谢谢你。

【问题讨论】:

  • 您为什么认为这是nginx 问题?配置只是将 POST 传递给后端。很可能是发出 405 响应的后端,
  • 事实上它很奇怪,它有时给我发 404 有时是 405。

标签: nginx http-status-code-405


【解决方案1】:

Nginx 以 HTTP 405 响应尝试访问静态资产的 POST 请求。

来自几年前的 Nginx 发布文档:

*) Feature: now Nginx returns the 405 status code for POST method requesting a static file only if the file exists.

绕过它的一种方法是添加此行,它会更改响应代码并将您发送到请求的 URI:

error_page 405 =200 $uri;

您可以在此处找到其他解决方案:

http://invalidlogic.com/2011/04/12/serving-static-content-via-post-from-nginx/

我希望这会有所帮助。

【讨论】:

  • 感谢您的回答,但我将应用的架构更改为只有一个端口。
猜你喜欢
  • 2023-04-04
  • 1970-01-01
  • 2018-08-23
  • 2015-03-19
  • 2012-05-31
  • 2018-01-28
  • 2015-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多