解决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这个参数的含义下面有解释
}
相关推荐
ximy133529 分钟前
AI服务器工作之整机部件(CPU+内存)
运维·服务器
weixin_4211334132 分钟前
bisheng 的 MCP服务器添加 或 系统集成
运维·服务器
岁月宁静2 小时前
深度定制:在 Vue 3.5 应用中集成流式 AI 写作助手的实践
前端·vue.js·人工智能
心易行者3 小时前
10天!前端用coze,后端用Trae IDE+Claude Code从0开始构建到平台上线
前端
ximy13353 小时前
AI服务器工作之线材的接口介绍
运维·服务器
leo__5203 小时前
skynet.start 的作用详细解析
服务器
ximy13353 小时前
AI服务器工作之ubuntu系统下的驱动安装
运维·服务器·ubuntu
²º²²এ松3 小时前
蓝牙低功耗(BLE)通信的中心设备/外围设备(连接角色)、主机/从机(时序角色)、客户端/服务器(数据交互角色)的理解
运维·服务器·数据库
saadiya~3 小时前
ECharts 实时数据平滑更新实践(含 WebSocket 模拟)
前端·javascript·echarts
fruge3 小时前
前端三驾马车(HTML/CSS/JS)核心概念深度解析
前端·css·html