代码之家  ›  专栏  ›  技术社区  ›  Pavel Perevezencev

nginx.conf中的两个位置

  •  2
  • Pavel Perevezencev  · 技术社区  · 7 年前

    我有两份水疗申请表。一个人管理,它叫 dashboard home .

    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
    

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

    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 回复  |  直到 7 年前
        1
  •  0
  •   Alexander Azarov    7 年前

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

    index index.html;
    
    location / {
      root /usr/share/nginx/html/home;
    }
    
    location /dashboard {
      root /usr/share/nginx/html;
    }