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