vue build后放到nginx运行报错:Failed to load resource: the server responded with a status of 405 (Not Allowed)

前端:vue cil3

后端:springboot 2

web服务器:nginx 1.15以上


未打包之前一切正常,打包后vue 发送post 请求到后台响应Failed to load resource: the server responded with a status of 405 (Not Allowed) 




405 一般是请求方式 不匹配....
试一试由post请求改为get请求,请求静态资源时用get请求..
查看前台和后台的 method允许方式...

后台是post 不打包之前是可以的

你提供的这些信息我只能判断出 postget方法 405..不贴源码...只看报错 就只能判断出这个结果.



vue 配置

module.exports = {

 // 基本路径

 publicPath:"./",

 // 输出文件目录

 outputDir: 'dist',

 devServer: {

  // port: 8080, // 端口号

  // host: 'localhost',

  https: false, // https:{type:Boolean}

  open: true, // 配置自动启动浏览器

  // proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理

  proxy: {

  

   "/api/": {

  

    target:'http://XXX.com:8085',

    ws: true,

    changeOrigin: true

    // pathRewrite: {

    //  // '^/api/': ''

    // }

   }

  }

 }



nginx 配置

upstream local {   

   server 203.195.220.120:80;

}

  server {

    listen    80; #/监听端口

    server_name xxx.com;#监听域名 localhost

root html;

    #charset koi8-r;


    #access_log logs/host.access.log main;

  

  

    location / {          

try_files $uri $uri/ /index.html ;

index index.html index.htm;

  

    }

server {
   listen       80;
   server_name  域名;
   
   location /{
      root /www/文件目录;
      index index.html index.htm index.php;
      error_page 405 =200 http://$host$request_uri;
   }
} 
网上说 nginx 不允许用post 获取静态资源..

我在网上查询了很多,按照网上的配置改了还是不行,按照上面改的也不行


 server {

    listen    8080;

    server_name localhost;

client_max_body_size 30m; #文件最大大小

proxy_connect_timeout 600; #设置超时时间


    location / {

      root  /opt/netbox/tomcat1.2/data/ROOT;

      index index.html index.htm;

    }

我的项目是这样配置的,完了root目录就是整个包目录,静态资源,地图瓦片等都可以访问