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