【问题标题】:How to host multiple Angular apps, subdomained w/ nginx container如何托管多个 Angular 应用程序,子域 w/ nginx 容器
【发布时间】:2018-07-27 21:14:42
【问题描述】:

所以我的情况如下 - 我有两个捆绑的 Angular 应用程序,位于 Docker 容器内。我想使用相同的 nginx 配置将它们托管在单独的子域(app1.example.com 和 app2.example.com,或者现在是 app1.localhost:8000 和 app2.localhost:8000)。

目前我正在捆绑它们并将它们粘贴在单独的目录中,

COPY --from=web-build-stage /app/dist/first-app/ /usr/share/nginx/html/first
COPY --from=web-build-stage /app/dist/second-app/ /usr/share/nginx/html/second

我的 nginx 配置被分成如下两台服务器 -

server {
  listen 80;
  server_name first.localhost;
  location / {
    root /usr/share/nginx/html/first
    index index.html index.htm;
    try_files $uri $uri/ /index.html =404;
  }
}

server {
  listen 80;
  server_name second.localhost;
  location / {
    root /usr/share/nginx/html/second
    index index.html index.htm;
    try_files $uri $uri/ /index.html =404;
  }
}

我也更新了我的主机文件 -

127.0.0.1   localhost
127.0.0.1   first.localhost
127.0.0.1   second.localhost

对于我的一生,我无法弄清楚为什么它没有正确代理或者我在哪里出错了配置。

有什么见解吗?

【问题讨论】:

    标签: angular docker nginx devops


    【解决方案1】:

    好吧,看来我已经找到了自己的答案,而我却是一个蹩脚的小姐。

    工作配置:

    server {
      listen 80;
      server_name first.localhost;
      root /usr/share/nginx/html/first;
      location / {
        index index.html index.htm;
        try_files $uri $uri/ /index.html =404;
      }
    }
    
    server {
      listen 80;
      server_name second.localhost;
      root /usr/share/nginx/html/second;
      location / {
        index index.html index.htm;
        try_files $uri $uri/ /index.html =404;
      }
    }
    

    注意:我将root 移出每个location 块(注明here),并且它们需要在路径末尾添加一个分号。不要错过!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-14
      • 2019-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-22
      • 2019-03-19
      • 1970-01-01
      相关资源
      最近更新 更多