Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping a url path to a server in nginx

Tags:

nginx

How can I map a URI of the form staging.example.com/siteA to a virtual server located at /var/www/siteA?

The main restriction is that I do not want to create a subdomain for siteA. All examples of nginx.conf I've seen so far rely on having a subdomain to do the mapping.

Thanks

like image 864
Bernard Avatar asked Oct 30 '13 07:10

Bernard


1 Answers

You may use the root directive within a location block, like this:

server {
    server_name staging.example.com;
    root /some/other/location;
    location /siteA/ {
        root /var/www/;
    }
}

Then http://staging.example.com/foo.txt points to /some/other/location/foo.txt, while http://staging.example.com/siteA/foo.txt points to /var/www/siteA/foo.txt.

Note that the siteA directory is still expected to exist on the filesystem. If you want http://staging.example.com/siteA/foo.txt to point to /var/www/foo.txt, you must use the alias directive:

location /siteA/ {
    alias /var/www;
}
like image 167
sjy Avatar answered Oct 09 '22 19:10

sjy