目前的环境: 两个 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', });
![]() | 1 hanxb 2024-07-15 11:49:22 +08:00 via Android server_name localhost; 不对吧 |
![]() | 2 Suaxi 2024-07-15 11:57:06 +08:00 error.log 看一下请求的静态资源路径,以前遇到过打包部署之后白屏这个问题,时间太久都忘记当时是怎么弄的了 |
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/ |