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、問題原因
因為這里請求的靜態(tài)文件采用的是post方法,nginx是不允許post訪問靜態(tài)資源。題話外,試著post訪問了下www.baidu.com發(fā)現(xiàn)頁面也是報錯,可以試著用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文件復制到sbin下 重啟nginx文章來源:http://www.zghlxwxcb.cn/news/detail-511235.html
- 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是一個HTTP 響應狀態(tài)代碼,表示服務器接收并識別了指定的請求HTTP 方法,但服務器拒絕了請求資源的特定方法。此代碼響應確認請求的資源有效且存在,但客戶端在請求期間使用了不可接受的 HTTP 方法。文章來源地址http://www.zghlxwxcb.cn/news/detail-511235.html
到了這里,關于Nginx的405 not allowed錯誤解決的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!