解决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这个参数的含义下面有解释
}
相关推荐
lightqjx6 分钟前
【前端】前端学习四之JavaScript(Web API -- DOM)
前端·javascript·学习
zzqssliu11 分钟前
Vue3 + Pinia 重构跨境代购前端:从taocarts的React方案学到的状态管理心得
前端·react.js·重构
Bert.Cai11 分钟前
Linux sort命令详解
linux·运维·服务器
开开心心就好12 分钟前
免费无广告的批量卸载与系统清理工具
linux·服务器·网络·智能手机·rabbitmq·excel·memcached
倔强的石头10613 分钟前
SenseNova-U1 实战体验:从网页版生成,到 Mac 踩坑,再到 CUDA 服务器跑通本地部署
运维·服务器·macos
IT_陈寒15 分钟前
SpringBoot自动配置偷偷给我埋了个坑
前端·人工智能·后端
PieroPc16 分钟前
通用产品标签打印 (为制衣厂 打印纸箱错印或不足 补打修改纸箱通用程序)html版
前端·javascript·vue.js
专注API从业者17 分钟前
用 Open Claw + 淘宝商品接口,快速实现电商商品监控与智能选品(附完整代码)
大数据·前端·数据结构·数据库
l167751685417 分钟前
天翼云服务器失联排查完整报告_事件报告
运维·服务器·云原生·云计算
muddjsv18 分钟前
前端开发语言使用流行度排行与分析
前端·javascript·typescript