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;
        }
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM