nginx加载vue3 打包后的静态文件

server {
    # 监听的端口号
    listen       3988;

    # 服务名称 改成自己服务器的地址
    server_name  127.0.0.1;
    

    # vuejs静态文件配置
    location / {
        # 静态文件的位置
        root   /srv/aiPowerWeb/;  
        
        # hash 模式下,找不到路径就切换到 index.html页面
        try_files $uri $uri/ @router;
        index  index.html index.htm;
    }
    # 对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件
    # 因此需要rewrite到index.html中,然后交给路由在处理请求资源
    location @router {
        rewrite ^.*$ /index.html last;
    }
}
博客中所涉及到的图片都有版权,请谨慎使用
原文地址:https://www.cnblogs.com/shuiche/p/15423829.html