vue项目打包发布后接口报405错误

vue项目打包发布后接口报405错误
vue项目前端做了代理打包后后台不识别报405 not allowed
vue.config.js文件配置

  devServer: {
    // host: "0.0.0.0", //项目运行时的本地地址
    // port: 8880, // 端口号
    //proxy:{'/api':{}},代理器中设置/api,项目中请求路径为/api的替换为target
    proxy: {
      '/api': {
        // target: "http://192.168.0.249:19029",//代理地址,这里设置的地址会代替axios中设置的baseURL
        target: process.env.VUE_APP_BASEURL_API,//代理地址,这里设置的地址会代替axios中设置的baseURL
        changeOrigin: true,// 如果接口跨域,需要进行这个参数配置
        //ws: true, // proxy websockets
        //pathRewrite方法重写url
        pathRewrite: {
          '^/api': "/"
          //pathRewrite: {'^/api': '/'} 重写之后url为 http://192.168.1.16:8085/xxxx
          //pathRewrite: {'^/api': '/api'} 重写之后url为 http://192.168.1.16:8085/api/xxxx
        },
    },

    https: false, // https:{type:Boolean}
    disableHostCheck: true,
    open: true, //配置自动启动浏览器
  },

default.conf文件配置

server {
    listen       9000;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files  $uri $uri/  @router;

    }
    location /api {
       rewrite ^/api/$  permanent;
       proxy_pass http://192.168.0.253:30001/warehouse/;
       proxy_redirect default;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header REMOTE-HOST $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    location @router {
        rewrite ^.*$ /index.html last;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
上一篇:Ubuntu 安装yii2 advanced版 遇到的坑


下一篇:ubuntu下nginx+php5的部署