7

I have a few sites. Each site has its own "server" section with a server_name that looks like this

server {
   ...
   server_name siteA.example.com;
   root /var/www/siteA;
   ...
}

I can therefore bring up the site using the url http://siteA.example.com

I however also need to bring up the site by using the url http://example.com/siteA How can this be done?

4

1 回答 1

24

下面有两个选项可以添加到您的配置中...

选项1:

server {
    ...
    server_name example.com;
    ...
    location /siteA {
        root /var/www/siteA;
        ...
    }
    location /siteB {
        root /var/www/siteB;
        ...
    }
    ...
}

选项 2:

server {
    ...
    server_name example.com;
    ...
    location /siteA {
        return       301 http://siteA.example.com$request_uri;
    }
    location /siteB {
        return       301 http://siteB.example.com$request_uri;
    }
    ...
}

第一个选项只是example.com/siteA额外提供服务,而第二个选项重定向到siteA.example.com

于 2013-10-01T08:09:38.730 回答