NGINX返回405 POST方法不允许

gudnpqoy  于 2023-01-08  发布在  Nginx
关注(0)|答案(2)|浏览(329)

我有这个默认的.conf:

server {
        listen  443 ssl;
        root /etc/nginx/json/;
        server_name    myserver.com;
        ssl_certificate /etc/ssl/certs/server.crt;
        ssl_certificate_key     /etc/ssl/private/server.key;
        ssl_protocols   TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers     HIGH:!aNULL:!MD5;
        location /platform/enabler/iam/token/generate/1.0.0
        {
                alias  /etc/nginx/json/generateToken.json;
        } }

使用GET方法调用API,响应正确。使用POST方法调用API,响应为:

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>

拜托,你能帮帮我吗?

tzcvj98z

tzcvj98z1#

您可以在配置中添加下面的代码行,让nginx使用静态文件来处理POST请求:

error_page 405 =200 $uri;
db2dz4w8

db2dz4w82#

这个解决方案对我不起作用,但是下面的配置起作用了(我使用nginx作为反向代理,所有东西都被固定了)

location / {
       include /etc/nginx/includes/common_location.conf;
       resolver 127.0.0.11 ipv6=off;
       set $upstream localhost:4200;
       proxy_pass http://$upstream;
    }

    location = /land {
       include /etc/nginx/includes/common_location.conf;
       proxy_method GET;
       resolver 127.0.0.11 ipv6=off;
       rewrite ^ https://example.com/land/ break;
    }

common_location.conf具有以下内容:

proxy_set_header    X-Real-IP           $remote_addr;
proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
proxy_set_header    X-Forwarded-Proto   $scheme;
proxy_set_header    Host                $host;
proxy_set_header    X-Forwarded-Host    $host;
proxy_set_header    X-Forwarded-Port    $server_port;
proxy_set_header    Connection          $http_connection;

相关问题