解决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这个参数的含义下面有解释
}
相关推荐
万物得其道者成3 小时前
前端大整数精度丢失:一次踩坑后的实战解决方案(`json-bigint`)
前端·json
鹏北海3 小时前
移动端 H5 响应式字体适配方案完全指南
前端
2301_805962934 小时前
arduino IDE如何设置代理
运维·服务器
柳杉5 小时前
使用AI从零打造炫酷医疗数据可视化大屏,源码免费拿!
前端·javascript·数据可视化
凌云拓界5 小时前
前端开发的“平衡木”:在取舍之间找到最优解
前端·性能优化·架构·前端框架·代码规范·设计规范
huaweichenai6 小时前
Linux安装http-server并部署html静态站点
linux·运维·服务器
zhengfei6116 小时前
【XSS payload 】一个经典的XSS payload
前端·xss
北冥湖畔的燕雀6 小时前
Linux权限与Vim,gcc以及make/makefile操作全解析
linux·运维·服务器
全栈老石7 小时前
手写一个无限画布 #1:坐标系的谎言
前端·canvas
XW01059997 小时前
4-11判断素数
前端·python·算法·素数