解决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这个参数的含义下面有解释
}
相关推荐
尘寰ya3 分钟前
什么是原型污染?如何防止原型污染?
前端·面试·原型模式
鸿蒙场景化示例代码技术工程师7 分钟前
实现实时语音转文字功能鸿蒙示例代码
前端
CZIDC11 分钟前
信创服务器-大国崛起,信创当道!
运维·服务器
ohMyGod_12312 分钟前
高阶函数/柯里化/纯函数
前端·react.js·前端框架
CsharpDev-奶豆哥16 分钟前
如何理解前端开发中的“换皮“
前端·css·css3
Mike_jia16 分钟前
Navicat 数据库管理全攻略:从基础操作到企业级应用实战
前端
Jackson_Mseven17 分钟前
如何从0到1搭建基于antd的monorepo库——使用rollup进行打包、lerna进行版本管理和发布(六)
前端·react.js·ant design
圆号手18 分钟前
手搓ag-grid带筛选的下拉选择器(类似企业版的agRichSelectCellEditor)
前端
Lestat18 分钟前
Vue Router 中 params 和 query 的区别
前端
静思己过19 分钟前
AutoDecimal:轻松解决 JavaScript 运算精度问题之toDecimal
前端·javascript