multiple roots for multiple sites

John Magolske listmail at b79.net
Sat May 15 02:31:00 MSD 2010


Hi,

I'm working on multiple sites & would like to specify different
roots for each one so that identical absolute urls such as
<a href="/index.html">Home</a> on each site don't all get
directed to the same /usr/local/nginx/html/index.html

ie,

navigate to http://localhost/site1 & the root will be
/usr/local/nginx/html/site1

navigate to http://localhost/site2 & the root will be
/usr/local/nginx/html/site2

I tried this:

    location /site1/ {
        root   /usr/local/nginx/html/site1;
        index  index.html index.htm;
    }

But navigating to http://localhost/site1 gets '404 Not Found'.
Without the above location directive, the site comes up fine
(other than than the aforementioned issue with absolute urls).

At this point I'm only running the sites locally on my laptop.

My nginx.conf looks like this:

worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

	    location /site1/ {
            root   /usr/local/nginx/html/site1;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}


Being new to nginx, I realize I'm probably overlooking something(s)
obvious with respect to how location directives & root works here.

TIA for any help,

John


-- 
John Magolske
http://B79.net/contact



More information about the nginx mailing list