解决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这个参数的含义下面有解释
}
相关推荐
trigger33310 分钟前
desk-health-web-community-post
前端
倒流时光三十年11 分钟前
Logback 系列(7):常用 Appender(控制台 / 文件 / 滚动文件)
java·前端·logback
Csvn37 分钟前
页面「穿越」之谜:React 中因 key 值不正确导致的渲染 Bug 排查实战
前端
浅水壁虎37 分钟前
前端技术_TypeScript(第一章)
前端
liulilittle1 小时前
论无知:分布式
服务器·网络·分布式·并发·通信·竞态
Web极客码1 小时前
MariaDB 将成为 cPanel 中的默认数据库
服务器·mariadb·cpanel
川石课堂软件测试1 小时前
安全测试|服务器安全加固方法
服务器·功能测试·测试工具·jmeter·mysql·web安全·单元测试
2401_858286112 小时前
OS79.【Linux】POSIX信号量
linux·运维·服务器
laboratory agent开发2 小时前
企业AI Agent落地前,先回答四个工程问题
java·前端·人工智能
微三云 - 廖会灵 (私域系统开发)2 小时前
电商系统国际化架构设计:多语言、多币种、多时区、多税制的全链路实现
java·前端·数据库