# Multiple roots for multiple sites

**URL:** <https://www.ruby-forum.com/t/multiple-roots-for-multiple-sites/188631>\
**Category:** NGINX\
**Created:** [May 15, 2010, 12:31am UTC](https://www.ruby-forum.com/t/multiple-roots-for-multiple-sites/188631 "2010-05-15T00:31:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Magolske](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@John\_Magolske](https://www.ruby-forum.com/u/John_Magolske)\
**Post date:** [May 15, 2010, 12:31am UTC](https://www.ruby-forum.com/t/multiple-roots-for-multiple-sites/188631/1 "2010-05-15T00:31:06Z")

</div>

Hi,

I’m working on multiple sites & would like to specify different  
roots for each one so that identical absolute urls such as  
[Home](https://www.ruby-forum.com/index.html) on each site don’t all get  
directed to the same /usr/local/nginx/html/index.html

ie,

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

navigate to [http://localhost/site2](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](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

> **[Contact](http://b79.net/contact)**
>
> Contact info for John Magolske

---

<div class="post-metadata">

**Author:** ![John\_Magolske](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@John\_Magolske](https://www.ruby-forum.com/u/John_Magolske)\
**Post date:** [May 15, 2010, 12:33am UTC](https://www.ruby-forum.com/t/multiple-roots-for-multiple-sites/188631/2 "2010-05-15T00:33:52Z")

</div>

Your config should look like that:

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

So that you want ever have to touch the configuration file even if new  
sites get created. It’s the easiest but there are drawbacks, if you can  
spot them.

---

<div class="post-metadata">

**Author:** ![John\_Magolske](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@John\_Magolske](https://www.ruby-forum.com/u/John_Magolske)\
**Post date:** [May 15, 2010, 1:01am UTC](https://www.ruby-forum.com/t/multiple-roots-for-multiple-sites/188631/3 "2010-05-15T01:01:32Z")

</div>

> Your config should look like that:
> 
> location / {  
> root /usr/local/nginx/html/$host;  
> index index.html index.htm;  
> }
> 
> So that you want ever have to touch the configuration file even if new  
> sites get created.

I just now tried the above directive in my nginx.conf, but end up  
getting ‘404 Not Found’ on all my sites.

John

–  
John Magolske

> **[contact b79](http://b79.net/contact)**

---

<div class="post-metadata">

**Author:** ![John\_Magolske](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@John\_Magolske](https://www.ruby-forum.com/u/John_Magolske)\
**Post date:** [May 15, 2010, 1:29am UTC](https://www.ruby-forum.com/t/multiple-roots-for-multiple-sites/188631/4 "2010-05-15T01:29:40Z")

</div>

Hello!

On Fri, May 14, 2010 at 03:31:00PM -0700, John Magolske wrote:

> navigate to [http://localhost/site2](http://localhost/site2) & the root will be  
> /usr/local/nginx/html/site2
> 
> I tried this:
> 
> ```
> location /site1/ {
> root /usr/local/nginx/html/site1;
> 
> ```

- 

```
    root /usr/local/nginx/html/site1;

```

- 

```
    alias /usr/local/nginx/html/site1/;

```

Directive “root” defines path to a server root (i.e. to “/”  
uri), and filename calculated as + .

Directive “alias” specifies path to a matched location, and  
filename calculated as + .

See here for details:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Maxim D.

---

<div class="post-metadata">

**Author:** ![John\_Magolske](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@John\_Magolske](https://www.ruby-forum.com/u/John_Magolske)\
**Post date:** [May 15, 2010, 12:11pm UTC](https://www.ruby-forum.com/t/multiple-roots-for-multiple-sites/188631/5 "2010-05-15T12:11:42Z")

</div>

> I just now tried the above directive in my nginx.conf, but end up  
> getting ‘404 Not Found’ on all my sites.

Well things are more complicated than that. What gets printed out in  
your error log?
