目錄
- 1、問題情況
- 2、問題原因
- 3、問題解決
- 4、拓展
1、問題情況
首先看到的頁面是nginx返回的頁面,得知錯誤要從nginx上來解決
<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、問題原因
因為這里請求的靜態文件采用的是post方法,nginx是不允許post訪問靜態資源。題話外,試著post訪問了下www.baidu.com發現頁面也是報錯,可以試著用get方式訪問
3、問題解決
現貼出三種解決方式,供大家選擇:
1、將405錯誤指向成功(我采用的這種方法解決的問題)
靜態server下的location加入 error_page 405 =200 $uri;
location / {
root /usr/share/nginx/html/cashier;
try_files $uri $uri/ /index.html;
index index.html index.htm;
error_page 405 =200 $request_uri;
}
2、修改nginx下src/http/modules/ngx_http_static_module.c文件
if (r->method & NGX_HTTP_POST) {
return NGX_HTTP_NOT_ALLOWED;
}
以上這一段注釋掉,重新編譯,將make install編譯生成的nginx文件復制到sbin下 重啟nginx
3、修改錯誤界面指向(網上多流傳這種方式,但是沒有改變請求方法,所以行不通,所以采用以下方法)
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;
}
}
4、拓展
405 Method Not Allowed是一個HTTP 響應狀態代碼,表示服務器接收并識別了指定的請求HTTP 方法,但服務器拒絕了請求資源的特定方法。此代碼響應確認請求的資源有效且存在,但客戶端在請求期間使用了不可接受的 HTTP 方法。






