Solution of 405 not allowed error in nginx

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

1. The first page you see is the page returned by nginx. You know that the error should be solved from nginx

Return to page:

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

2. Check the information online, because the static file requested here uses the post method, nginx does not allow post to access the static resources. In addition to the topic, I try to post an interview www.baidu.com Found that the page is also an error

3. Three solutions are posted

1. Pointing 405 error to success

Add error to location in static server_ page 405 =200 $uri;

location ~ ^/better/.*\.(htm|html|gif|jpg|jpeg|png|ico|rar|css|js|zip|txt|flv|swf|doc|ppt|xls|pdf|json|ico|htc)$ {
<span style="white-space:pre">	</span>root D:/code/BetterjrWeb;
<span style="white-space:pre">	</span>error_page 405 =200 $uri;
}

2. Modify the Src/HTTP/modules/NGX HTTP static module. C event under nginx

if (r->method & NGX_HTTP_POST) {
     return NGX_HTTP_NOT_ALLOWED;
}

Note out this paragraph, recompile, do not make install, copy the nginx file generated by compilation to SBIN, restart nginx

3. Modify the wrong interface direction (this way is widely spread on the Internet, but the request method is not changed, so it is not feasible, so the following method is adopted)

upstream static_backend {
    server localhost:80;
}

server {
    listen 80;
    # ...
    error_page 405 =200 @405;
    location @405 {
        root /srv/http;
        proxy_method GET;
        proxy_pass http://static_backend;
    }
}

Similar Posts: