解决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这个参数的含义下面有解释
}
相关推荐
_XU11 分钟前
AI工具如何重塑我的开发日常
前端·人工智能·深度学习
L Jiawen24 分钟前
【Golang基础】基础知识(下)
服务器·开发语言·golang
C_心欲无痕27 分钟前
vue3 - defineExpose暴露给父组件属性和方法
前端·javascript·vue.js·vue3
鹿人戛39 分钟前
HarmonyOS应用开发:相机预览花屏问题解决案例
android·前端·harmonyos
萌萌哒草头将军1 小时前
绿联云 NAS 安装 AudioDock 详细教程
前端·docker·容器
GIS之路1 小时前
GIS 数据转换:使用 GDAL 将 GeoJSON 转换为 Shp 数据
前端
haimin03712 小时前
linux设置CPU固定频率
linux·运维·服务器
朴shu2 小时前
Luckysheet 远程搜索下拉 控件开发 : 揭秘二开全流程
前端
一条咸鱼¥¥¥2 小时前
【运维经验】服务器磁盘做镜像的方法
运维·服务器·windows·经验分享
渣渣盟2 小时前
NFS服务器配置全攻略:从入门到精通
linux·运维·服务器