關(guān)于nginx報錯405?not?allowed解決方法總結(jié)
一、報錯原因提示: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文件復制到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、跨服務調(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為后端服務地址
proxy_pass http://ip+端口$request_uri ;
}
}總結(jié)
到此這篇關(guān)于關(guān)于nginx報錯405 not allowed解決的文章就介紹到這了,更多相關(guān)nginx報錯405 not allowed內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
nginx配置location總結(jié)location正則寫法及rewrite規(guī)則寫法
本文詳細講述了Nginx location正則寫法,Nginx 的Rewrite規(guī)則以及Nginx.conf中if指令與全局變量2018-10-10
Nginx偽靜態(tài)配置和常用Rewrite偽靜態(tài)規(guī)則集錦
偽靜態(tài)是一種可以把文件后綴改成任何可能的一種方法,如果我想把php文件偽靜態(tài)成html文件,這種相當簡單的,下面我來介紹nginx 偽靜態(tài)配置方法有需要了解的朋友可參考。2014-06-06
使用nginx正向代理實現(xiàn)內(nèi)網(wǎng)域名轉(zhuǎn)發(fā)過程解析
這篇文章主要介紹了使用nginx正向代理實現(xiàn)內(nèi)網(wǎng)域名轉(zhuǎn)發(fā)過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-08-08
Windows Server 2016 MySQL數(shù)據(jù)庫安裝配置詳細安裝教程
這篇文章主要介紹了Windows Server 2016 MySQL數(shù)據(jù)庫安裝配置詳細安裝教程,需要的朋友可以參考下2017-08-08

