请教大家一个关于前端项目部署的问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iwasthere
V2EX    问与答

请教大家一个关于前端项目部署的问题

  •  
  •   iwasthere 2024-07-15 11:21:40 +08:00 1204 次点击
    这是一个创建于 457 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前的环境: 两个 windows 虚拟机 A,B A 是安装了 nginx ,并且在 nginx 下的 html 放了一个名为 Bi 的文件夹,里面是前端项目打包后的 dist 文件

    问题: 在 A 服务器本地访问 localhost 或者本机 ip 可以正确的打开界面,但是在 B 虚拟机里访问 A 的 ip 地址(模拟用户访问)打开的界面却是空白,看了 network 有成功访问到 index.htmlwen 文件。请问这是哪里出了问题?

    nginx 配置:

    user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; location / { root D:/nginx-1.26.1/html/Bi; index index.html index.htm; try_files $uri $uri/ /index.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } 

    前端项目 config

    export default defineConfig({ outputPath: 'dist', publicPath: '/', manifest: { basePath: '/', }, routes: [ { path: "/", component: "@/pages/index/index.tsx" }, ], npmClient: 'yarn', }); 
    6 条回复    2024-07-15 14:19:12 +08:00
    hanxb
        1
    hanxb  
       2024-07-15 11:49:22 +08:00 via Android
    server_name localhost;
    不对吧
    Suaxi
        2
    Suaxi  
       2024-07-15 11:57:06 +08:00
    error.log 看一下请求的静态资源路径,以前遇到过打包部署之后白屏这个问题,时间太久都忘记当时是怎么弄的了
    iwasthere
      nbsp; 3
    iwasthere  
    OP
       2024-07-15 13:25:55 +08:00
    @hanxb 请问是哪里不对?
    iwasthere
        4
    iwasthere  
    OP
       2024-07-15 13:26:18 +08:00
    @Suaxi 好的,谢谢提示
    wangmn
        5
    wangmn  
       2024-07-15 13:59:08 +08:00
    是不是 index.html 放到这个路径了 D:/nginx-1.26.1/html/Bi/dist 了,前端改相对路径打包。或者 index.html 这级目录文件直接放到 D:/nginx-1.26.1/html/Bi/
    iwasthere
        6
    iwasthere  
    OP
       2024-07-15 14:19:12 +08:00
    @wangmn 没 Bi 下面就是 dist 里面的所有文件,包含 index.html,你说的改相对路径打包指的是什么配置呢?
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5585 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 06:04 PVG 14:04 LAX 23:04 JFK 02:04
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86