解决nginx 部署前端post请求405 not allowed

原因:nginx 静态资源访问不支持post请求。

解决方案:

html 复制代码
       upstream static_backend {
            server localhost:9095;
       }

       location / {
            root  /usr/local/dist;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
            error_page 405 =200 @405;  #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://localhost:9095$request_uri ;
       }

或者

javascript 复制代码
location / {
        root /usr/share/nginx/html/cashier;
        try_files $uri $uri/ /index.html;
        index index.html index.htm;
        error_page 405 =200  $request_uri; // $request_uri这个参数的含义下面有解释
}
相关推荐
zl0_00_05 分钟前
xss-lab
前端·网络·xss
爱上你家菜包11 分钟前
Electron一小时快速上手
前端·javascript·electron
陈琦鹏12 分钟前
Vue3+Vite开发Electron桌面端问题记录
前端·javascript·electron
lqlj223326 分钟前
Linux常用命令
linux·运维·服务器
obboda1 小时前
使用haproxy实现MySQL服务器负载均衡
服务器·mysql·负载均衡
wanhengidc1 小时前
怎样分辨是否是高防服务器?
运维·服务器·网络
itachi-uchiha1 小时前
深入理解 Linux 中的 last 和 lastb 命令
java·linux·服务器
gma9991 小时前
【GB28181】 SIP信令服务器
运维·服务器
狼性书生2 小时前
uniapp vue3实现的一款数字动画调节器件,支持长按、单点操作,提供丝滑的增减动画效果
前端·vue.js·微信小程序·小程序·uni-app
Jelena157795857922 小时前
爬虫获取微店商品快递费 item_feeAPI 接口的完整指南
开发语言·前端·爬虫