vue 发布到iis/nginx调用post方法出现405的解决方案

一开始了解了一下网上说什么静态文件不能用post只能用get访问,所以后来配置了nginx的反向代理,虽然在vue的devserver可以配置proxy,但是那只针对于开发环境,生产环境无效,具体代码如下,希望可以帮助大家:

    server {
        listen 8082;
        server_name localhost;
        location /{
            root E:/DevSoft/nginx-1.17.7/html/dist;
            index index.html index.htm;
            #不写这句,history模式请求路由会变成直接请求后台的路由导致404
            try_files $uri $uri/ /index.html;
            autoindex on;
        }
        #反向代理,解决跨域问题,不配置的话也容易出现405的问题
        location ~/api/{
            proxy_pass http://localhost:49449;
        }
        
        location ~/connect/token{
            proxy_pass http://192.168.150.129:8080;
        }
    }

猜你喜欢

转载自www.cnblogs.com/llcdbk/p/12289934.html
今日推荐