Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx Routing path to server

Tags:

nginx

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?

like image 948
Bernard Avatar asked Oct 01 '13 04:10

Bernard


1 Answers

Two options to add to your config below ...

Option 1:

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

Option 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;
    }
    ...
}

First option simply serves from example.com/siteA in addition while second option redirects to siteA.example.com

like image 115
Dayo Avatar answered Oct 03 '22 20:10

Dayo