配置 Nginx 以使用多个目录

Configure Nginx to use several directories

有配置nginx的时候参考http://example.com/sellers 必须从文件夹 /data/sellers 中提供服务器 在另一种情况下 - 文件夹 /data/customers

Nginx 配置:

    server {
    listen       80;
    server_name  localhost;
    index index.html index.htm home.html;

    location /sellers {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        rewrite ^/sellers/?(.*) / break;
        root   /data/sellers;
    }

    location / {
        root   /data/customers;
    }
}

一切正常,但不完全正确:当访问服务器时,卖家以某种方式使用文件夹 /data/customers/index.html 中的 index.html 以及文件夹的所有其余部分 /data/sellers(这是正确的) 有什么问题?为什么nginx拿错了index.html文件,尽管其余的格都对?

回答

server {
  listen       80;
  server_name  localhost;
  index index.html index.htm home.html;
  root /data/customers;

  location /sellers {
    alias /data/sellers;
  }
}