NGINX-如何在同一个基本URL中服务多个应用程序-SPA

时间:2018-07-16 21:50:25

标签: nginx routing single-page-application nginx-location

我的NGINX设置中有两个位置:

位置/ APP_B

位置/

一个用于应用程序A(/),一个用于应用程序B。我能够正确设置,因此URL中的不同子目录将获得正确的响应,但是,我仍然遇到浏览器尝试下载所有文件的行为。捆绑我的应用程序在/目录中的文件。

nginx app conf中有什么方法可以告诉我所有对静态文件的请求都映射到了新的URL?

很高兴收到任何建议。谢谢。

1 个答案:

答案 0 :(得分:0)

是的,您可以这样做。您需要使用location块。我不确定您的网址是什么,但是您最终应该得到这样的内容:

location /APP_B/static/ {
  proxy_pass http://127.0.0.1:1111/static;
  proxy_set_header    Host            $host;
  proxy_set_header    X-Real-IP       $remote_addr;
  proxy_set_header    X-Forwarded-for $remote_addr;
}

location /static/ {
  proxy_pass http://127.0.0.1:2222/static;
  proxy_set_header    Host            $host;
  proxy_set_header    X-Real-IP       $remote_addr;
  proxy_set_header    X-Forwarded-for $remote_addr;
}
相关问题