解决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_陈寒3 分钟前
Vite动态导入差点让我秃头,原来问题出在这
前端·人工智能·后端
Android系统攻城狮27 分钟前
Linux PipeWire深度解析之pw_stream_new调用流程与实战(七十八)
linux·运维·服务器·音频进阶·pipewire音频实战进阶
白泽_hunter38 分钟前
项目里最常见的 5 个 this 指向坑:从规则到实战彻底讲透
前端
宿67444 分钟前
vue3-pinia
前端·vue.js
白泽_hunter1 小时前
搞懂 JS 数据类型:从 typeof 到手写完整类型判断,一张图理清
前端
日光倾1 小时前
TypeScript 随手记 —— 1
前端·javascript·typescript
自学it的攻城狮2 小时前
elpis-core ,koa实现的系统底座, 沉淀80% 的通用能力,剩下20% 用于定制化开发
前端
weipt2 小时前
从ollama到llama.cpp
linux·服务器·llama
CappuccinoRose2 小时前
模块化体系
前端·import·export·es modules
AIDANHANG3 小时前
放开靠时间戳对日志前先核请求ID跨服务传播与采样关联
前端·人工智能