Vue Nginx 跨域配置小計


正式環境中Nginx配置 VUE打包后dist目錄配置跨域, 同時設置靜態資源緩存

server {
    listen       80;
    server_name  XXX.top www.XXX.top;

    sendfile on;
    #charset koi8-r;
    access_log  /var/log/nginx/log/sycity.log  main;

    root /sycity/RuoYi-Vue/ruoyi-ui/dist;

    location / {
        #root /sycity/RuoYi-Vue/ruoyi-ui/dist;
        index index.html;
        try_files $uri $uri/ /index.html; #Vue路由history模式添加該行, 若不是則移除該行
    }

    #以下配置是請求代理跨域 http://xxx.top/prod-api/XXX  反向代理請求http://127.0.0.1:8080/XXX 
    location ^~ /prod-api {
       rewrite ^.+prod-api/?(.*)$ /$1 break;
       include uwsgi_params;
       proxy_pass http://127.0.0.1:8080;
    }

    #靜態資源
    location ~ .*\.(js|css|jpg|png|gif)$ {
        expires 2d;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM