解决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这个参数的含义下面有解释
}
相关推荐
weixin_489690023 分钟前
MicroSIP自定义web拨打协议
服务器·前端·windows
秋天枫叶357 分钟前
【k8s集群Docker + cri-dockerd】服务器重启或关机后 apiserver/controller/scheduler 无法自动恢复
linux·运维·服务器·容器·kubernetes·bug
赋创小助手8 分钟前
超微2U高密度服务器AS-2126HS-TN评测(双AMD EPYC 9005 Turin)
运维·服务器·人工智能·深度学习·神经网络·自然语言处理·架构
松涛和鸣10 分钟前
59、 IMX6ULL按键驱动开发:轮询到中断的实现
linux·服务器·c语言·arm开发·数据库·驱动开发
幻云201016 分钟前
Python机器学习:筑基与实践
前端·人工智能·python
web小白成长日记18 分钟前
Vue3中如何优雅实现支持多绑定变量和修饰符的双向绑定组件?姜姜好
前端·javascript·vue.js
LcVong20 分钟前
C# 基于MemoryMappedFile实现进程间通信(服务端+客户端完整范例)
linux·服务器·c#
晴天飛 雪23 分钟前
Spring Boot 接口耗时统计
前端·windows·spring boot
0思必得032 分钟前
[Web自动化] Selenium模拟用户的常见操作
前端·python·selenium·自动化
狂放不羁霸33 分钟前
Tailscale | 校园网外笔记本借助校园网内主机连接实验室服务器
运维·服务器·vscode