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