V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
iwasthere
V2EX  ›  问与答

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

  •  
  •   iwasthere · 79 天前 · 853 次点击
    这是一个创建于 79 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前的环境: 两个 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  
       79 天前 via Android
    server_name localhost;
    不对吧
    Suaxi
        2
    Suaxi  
       79 天前
    error.log 看一下请求的静态资源路径,以前遇到过打包部署之后白屏这个问题,时间太久都忘记当时是怎么弄的了🐶
    iwasthere
        3
    iwasthere  
    OP
       79 天前
    @hanxb 请问是哪里不对?
    iwasthere
        4
    iwasthere  
    OP
       79 天前
    @Suaxi 好的,谢谢提示
    wangmn
        5
    wangmn  
       79 天前
    是不是 index.html 放到这个路径了 D:/nginx-1.26.1/html/Bi/dist 了,前端改相对路径打包。或者 index.html 这级目录文件直接放到 D:/nginx-1.26.1/html/Bi/
    iwasthere
        6
    iwasthere  
    OP
       79 天前
    @wangmn 没 Bi 下面就是 dist 里面的所有文件,包含 index.html,你说的改相对路径打包指的是什么配置呢?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1921 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 08:22 · PVG 16:22 · LAX 01:22 · JFK 04:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.