柚子快報激活碼778899分享:運維 關(guān)于nginx報錯405
柚子快報激活碼778899分享:運維 關(guān)于nginx報錯405
一、報錯原因提示:nginx 解決 405 not allowed錯誤
????????問題產(chǎn)生原因:因為這里請求的靜態(tài)文件采用的是post方法,nginx是不允許post訪問靜態(tài)資源。題話外,試著post訪問了下www.baidu.com發(fā)現(xiàn)頁面也是報錯,可以試著用get方式訪問
二、解決方式(四種)
1、、將405錯誤指向成功 ?? ?? ?? 靜態(tài)server下的location加入 error_page 405 =200 $uri;(說白了就是強制將405錯誤用200代替了)
location / {
root /usr/locai/nginx/html/kt;
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、允許nginx的post請求訪問靜態(tài)資源,個人感覺是強制把post請求變get了
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、跨服務(wù)調(diào)用報錯解決(親測有效)
server {
listen 8010;
server_name localhost;
location / {
root /usr/local/system/efe/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
error_page 405 =200 @405;
location @405 {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#ip為后端服務(wù)地址
proxy_pass http://ip+端口$request_uri ;
}
}
柚子快報激活碼778899分享:運維 關(guān)于nginx報錯405
參考鏈接
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。