简体   繁体   English

位置路径 nginx 无法服务 static 文件 vueJS

[英]Location path nginx cannot serve static file vueJS

I have 2 docker containers that contain 2 websites, a new website and an old website.我有 2 个 docker 容器,其中包含 2 个网站,一个新网站和一个旧网站。

New website run on port 8000 (Laravel) and the old website run on port 8001 (VueJS).新网站运行在 8000 端口(Laravel),旧网站运行在 8001 端口(VueJS)。

I want the location / proxy pass to the new website and the location /old proxy pass to the old website.我希望将位置/代理传递给新网站,并将位置/旧代理传递给旧网站。

For new website, it can be accessed properly.对于新网站,可以正常访问。

location / {
  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;
  proxy_pass              http://localhost:8000;
}

but for the old website, assets, images, fonts are still 404.但是对于旧网站,资产,图像,fonts 仍然是 404。

location /old {
  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;
  proxy_pass              http://localhost:8001;
}

404 because when access https://my.domain.net/old/ , the asset that should be called is https://my.domain.net/old/asset/images/logo.png 404 因为访问https://my.domain.net/old/时,应该调用的资产是https://my.domain.net/old/asset/images/logo.png

But this is still https://my.domain.net/asset/images/logo.png so that 404 is not found.但这仍然是https://my.domain.net/asset/images/logo.png所以找不到 404。

Please help.请帮忙。

location ~* '^/(assets|images|fonts)/' {
  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;
  proxy_pass              http://localhost:8001;
}

I inspect element, for location /old the assets redirect to my.domain.net/asset.css.我检查元素,对于位置 /old,资产重定向到 my.domain.net/asset.css。 (absolutely 404 not found) (绝对404找不到)

It looks like your localhost:8001 redirects.看起来您的 localhost:8001 重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM