解决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这个参数的含义下面有解释
}
相关推荐
IT_陈寒6 分钟前
React开发者都在偷偷用的5个性能优化黑科技,你知道几个?
前端·人工智能·后端
还是大剑师兰特35 分钟前
Vue3 前端专属配置(VSCode settings.json + .prettierrc)
前端·vscode·json
前端小趴菜051 小时前
vue3项目优化方案
前端·javascript·vue.js
Mr_Swilder1 小时前
WebGPU 基础 (WebGPU Fundamentals)
前端
张3蜂1 小时前
HTML5语义化标签:现代网页的骨架与灵魂
前端·html·html5
chinesegf1 小时前
DNS 验证验证SSL证书
linux·服务器·网络
悟空瞎说1 小时前
我用 PixiJS 撸了个圆桌会议选座系统,从 0 到 1 踩坑全复盘
前端
码云之上1 小时前
从 SPA 到全栈:AI 时代的前端架构升级实践
前端·架构·ai编程
小陈同学呦2 小时前
关于如何使用CI/CD做自动化部署
前端·后端
前端Ah2 小时前
记 华为鸿蒙机型小程序使用uni.createInnerAudioContext() 播放音频播放两次的问题
前端