# Problem when using subfolder

**URL:** <https://www.ruby-forum.com/t/problem-when-using-subfolder/225269>\
**Category:** NGINX\
**Created:** [December 25, 2012, 5:04pm UTC](https://www.ruby-forum.com/t/problem-when-using-subfolder/225269 "2012-12-25T17:04:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [December 25, 2012, 5:04pm UTC](https://www.ruby-forum.com/t/problem-when-using-subfolder/225269/1 "2012-12-25T17:04:22Z")

</div>

Hi There,

need to solve the following Problem:

location / should point to /var/www/myfirstside  
and location /subside should point to /var/www/mysecondside

I have no idea how to solve this.

I tried:

location / {  
root /var/www/myfirstside  
}

location /subside {  
root /var/www/mysecondside  
}

but this doesn’t work because nginx send all requests for /subside to  
/var/www/mysecondside/subside …

Could anybody help me?

THX allot  
Pascal

Posted at Nginx Forum:

> **[Problem when using subfolder](https://forum.nginx.org/read.php?2,234428,234428#msg-234428)**
>
> Hi There, need to solve the following Problem: location / should point to /var/www/myfirstside and location /subside should point to /var/www/mysecondside I have no idea how to solve this. I tried: location / {

---

<div class="post-metadata">

**Author:** ![pascalturbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@pascalturbo](https://www.ruby-forum.com/u/pascalturbo)\
**Post date:** [December 25, 2012, 5:08pm UTC](https://www.ruby-forum.com/t/problem-when-using-subfolder/225269/2 "2012-12-25T17:08:27Z")

</div>

Hello!

On Tue, Dec 25, 2012 at 11:04:03AM -0500, PascalTurbo wrote:

> Could anybody help me?

Try “alias”:

```
location / {
    root /var/www/myfirstside;
}

location /subside/ {
    alias /var/www/mysecondside/;
}

```

See [Module ngx\_http\_core\_module](http://nginx.org/r/alias) for details.

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![pascalturbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@pascalturbo](https://www.ruby-forum.com/u/pascalturbo)\
**Post date:** [December 25, 2012, 5:55pm UTC](https://www.ruby-forum.com/t/problem-when-using-subfolder/225269/3 "2012-12-25T17:55:48Z")

</div>

Ah IC your appending a context path, but since this isnt Java, Im still  
curious as to why

---

<div class="post-metadata">

**Author:** ![pascalturbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@pascalturbo](https://www.ruby-forum.com/u/pascalturbo)\
**Post date:** [December 25, 2012, 5:53pm UTC](https://www.ruby-forum.com/t/problem-when-using-subfolder/225269/4 "2012-12-25T17:53:27Z")

</div>

ngnix docs state that the closest match will always be found in location  
phrases

So why is alias needed?

---

<div class="post-metadata">

**Author:** ![pascalturbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@pascalturbo](https://www.ruby-forum.com/u/pascalturbo)\
**Post date:** [December 25, 2012, 7:05pm UTC](https://www.ruby-forum.com/t/problem-when-using-subfolder/225269/5 "2012-12-25T19:05:54Z")

</div>

Hello!

On Tue, Dec 25, 2012 at 08:52:32AM -0800, Bill C. wrote:

> ngnix docs state that the closest match will always be found in location phrases
> 
> So why is alias needed?

Normally (with root specified) nginx constructs file name as  
 + . This allows to specify root at any level, and it  
will work without surprises via configuration inheritance. I.e.

```
root /path/to;

location /foo/ {
    # ...
}

```

and

```
location /foo/ {
    root /path/to;
}

```

and even

```
location /foo/ {
    ...
    location /foo/bar {
        root /path/to;
    }
}

```

all will result in a “/foo/bar.txt” request being mapped into  
a “/path/to/foo/bar.txt” file.

In contrast, alias replaces part of the URI matched by a location,  
and file name will be + . This is  
more fragile as things change as you move the alias directive to  
another place, but allows to map URI to file system if some parts  
of the URI needs to be modified, e.g. in configuration like

```
location /foo/ {
    alias /path/to/baz/;
}

```

request to “/foo/bar.txt” will be mappend into  
“/path/to/baz/bar.txt” file.

It is generally recommended to use “root”, except in situations  
like thread starter has, i.e. when URI needs to be modified when  
mapping to a file system.

See here for docs:

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#root)**
>
> This directive appeared in version 1.11.8.

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#alias)**
>
> This directive appeared in version 1.11.8.

[…]

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.
