Nginx的405 not allowed錯誤解決方法
目錄
- 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、問題原因
因?yàn)檫@里請求的靜態(tài)文件采用的是post方法,nginx是不允許post訪問靜態(tài)資源。題話外,試著post訪問了下www.baidu.com發(fā)現(xiàn)頁面也是報(bào)錯,可以試著用get方式訪問
3、問題解決
現(xiàn)貼出三種解決方式,供大家選擇:
1、將405錯誤指向成功(我采用的這種方法解決的問題)
靜態(tài)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文件復(fù)制到sbin下 重啟nginx
3、修改錯誤界面指向(網(wǎng)上多流傳這種方式,但是沒有改變請求方法,所以行不通,所以采用以下方法)
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是一個(gè)HTTP 響應(yīng)狀態(tài)代碼,表示服務(wù)器接收并識別了指定的請求HTTP 方法,但服務(wù)器拒絕了請求資源的特定方法。此代碼響應(yīng)確認(rèn)請求的資源有效且存在,但客戶端在請求期間使用了不可接受的 HTTP 方法。
到此這篇關(guān)于Nginx的405 not allowed錯誤解決方法的文章就介紹到這了,更多相關(guān)Nginx 405 not allowed內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!
