Fork me on GitHub

若依Vue3部署到Nginx

代码地址

https://github.com/AutKevin/RuoYi-Vue3
image

调试阶段

yarn run dev

直接运行代码,不需要编译
image

编译预览

#使用stage环境编译到dist
yarn run build:stage
#使用prod环境编译到dist
yarn run build:prod
#预览编译后的项目文件
yarn run preview

编译后文件列表
image

nginx配置

编译后生成的dist文件夹部署到nginx服务器上,并配置nginx.conf配置文件

    server {
    listen 88;
    server_name localhost;

    # 静态资源路径
    root D:\\ruoyi-vue\\ruoyi-ui3\\dist;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }

    # 接口代理:把 /stage-api 代理到后端,如果是正式环境改为prod-api
    location /stage-api/ {
        rewrite ^/stage-api/(.*)$ /$1 break;
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # gzip 启用建议
    gzip on;
    gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    }
posted @ 2025-07-13 11:00  秋夜雨巷  阅读(121)  评论(0)    收藏  举报