解决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这个参数的含义下面有解释
}
相关推荐
D***t1317 分钟前
React图像处理案例
前端
万少1 小时前
我是如何使用 Trae IDE 完成《流碧卡片》项目的完整记录
前端·后端·ai编程
9***Y481 小时前
前端微服务
前端·微服务·架构
ByteCraze1 小时前
我整理的大文件上传方案设计
前端·javascript
郝学胜-神的一滴1 小时前
Linux命名管道:创建与原理详解
linux·运维·服务器·开发语言·c++·程序人生·个人开发
宾有为1 小时前
【Linux】Linux 常用指令
linux·服务器·ssh
wanhengidc1 小时前
云手机性能如何?
运维·服务器·科技·智能手机·云计算
前端小白۞1 小时前
vue2 md文件预览和下载
前端·javascript·vue.js
十里-1 小时前
为什么创建1x1的gif图片,和png 或者jpg图片有什么区别
前端
ajassi20001 小时前
开源 Linux 服务器与中间件(十三)FRP服务器、客户端安装和测试
linux·服务器·开源