nginx.conf中的两个位置

时间:2018-10-07 20:12:53

标签: nginx

我有两个SPA应用程序。单个用于管理,称为<div class="content"> <h1><span id="caption"> </span></h1> </div>,第二个用于用户称为dashboard

在Docker中,我构建了每个应用程序。

home

在Docker容器中的文件夹结构如下:

COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build-home /usr/src/app/dist /usr/share/nginx/html/home
COPY --from=build-dashboard /usr/src/app/dist /usr/share/nginx/html/dashboard

我的root@605813e61476:/usr/share/nginx/html# ls 50x.html dashboard home index.html root@605813e61476:/usr/share/nginx/html# 看起来像这样:

nginx.conf

我希望用户访问http { server { listen 80 default_server; listen [::]:80 default_server; location / { alias /usr/share/nginx/html/home/; try_files $uri /index.html; } location /dashboard { alias /usr/share/nginx/html/dashboard/; try_files $uri /index.html; } # location /api { # rewrite ^/api/?(.*) /$1 break; # proxy_pass http://api:5000; # proxy_redirect off; # } } } 时看到/dashboard/*,在其他情况下看到/usr/share/nginx/html/ dashboard。现在,当我访问/usr/share/nginx/html/home时,我会看到家庭应用程序。我在做什么错了?

1 个答案:

答案 0 :(得分:0)

我建议您保持简单。由于您在两个目录中都有静态资源,请尝试以下操作:

index index.html;

location / {
  root /usr/share/nginx/html/home;
}

location /dashboard {
  root /usr/share/nginx/html;
}