解决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这个参数的含义下面有解释
}
相关推荐
Carlos_sam24 分钟前
OpenLayers:封装Tooltip
前端·javascript
工呈士38 分钟前
MobX与响应式编程实践
前端·react.js·面试
嘉小华39 分钟前
Android Lifecycle 使用
前端
Sherry00741 分钟前
实时数据传输协议:WebSocket vs MQTT
前端·websocket
然我41 分钟前
JavaScript的OOP独特之道:从原型继承到class语法
前端·javascript·html
腹黑天蝎座43 分钟前
如何更好的实现业务中图片批量上传需求
前端
嘉小华44 分钟前
Android Lifecycle 源码解析
前端
不_喜1 小时前
游戏开发零散知识点和优化记录
前端
去伪存真1 小时前
提交规范靠吼没用,看我用“shell+husky螺丝刀”,一键给40多个项目上锁
前端·eslint
翠莲1 小时前
vue3+TS+eslint9配置
前端·代码规范