# Configuring nginx for different rails apps under same domain

**URL:** <https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861>\
**Category:** NGINX\
**Created:** [November 21, 2007, 8:10am UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861 "2007-11-21T08:10:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![archana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@archana](https://www.ruby-forum.com/u/archana)\
**Post date:** [November 21, 2007, 8:10am UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861/1 "2007-11-21T08:10:44Z")

</div>

i want to know how to configure nginx for different rails app under the  
same domain.  
for example:  
1)Rails application 1 [http://mydomain.com/app1](http://mydomain.com/app1)  
2)Rails application 2 [http://mydomain.com/app2](http://mydomain.com/app2)

Below is my enginx configuration .i want to know where iam goin wrong  
as i’m able to go in my home page but not able to navigate from login  
and signup pages.

NGINX.CONF:

#user nobody;  
worker\_processes 1;

#error\_log logs/error.log;  
error\_log logs/error.log notice;  
#error\_log logs/error.log info;

pid logs/nginx.pid;

events {  
worker\_connections 1024;  
use epoll;  
}

http {  
include conf/mime.types;  
default\_type application/octet-stream;

```
log_format main '$remote_addr - $remote_user [$time_local]

```

$request ’  
'“$status” $body\_bytes\_sent “$http\_referer” ’  
‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

```
access_log logs/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript

```

text/xml application/xml application/xml+rss text/javascript;

```
server_names_hash_bucket_size 128; # this seems to be required for

```

vhosts

```
    # mongrel cluster for domain.in
 upstream mongrel_cluster{
            server 127.0.0.1:4000 ;
            server 127.0.0.1:4001 ;
            server 127.0.0.1:4002 ;
                             }

```

#domain.in/app1 server  
server {  
listen 192.168.0.196:80;  
client\_max\_body\_size 50M;  
server\_name www.domain.in domain.in;  
root /var/www/domain.in/app1/public;  
#charset koi8-r;

```
    access_log logs/access.log main;
    rewrite_log on;

    location /app1/ {
            proxy_pass http://mongrel_cluster/;
              proxy_redirect off;
                      }

   location ~

```

^/(images|javascripts|js|css|stylesheets|tiles|static|demo)/ {  
root /var/www/domain.in/app1/public;

```
        expires 30d;
    }

    location ~*

```

^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$  
{  
root /var/www/domain.in/app1/public;  
expires 30d;  
}

```
    location / {
        proxy_pass http://mongrel_cluster;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html

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

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

```

}

---

<div class="post-metadata">

**Author:** ![archana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@archana](https://www.ruby-forum.com/u/archana)\
**Post date:** [November 21, 2007, 9:15am UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861/2 "2007-11-21T09:15:50Z")

</div>

On Wed, 2007-11-21 at 08:10 +0100, Archana Balaji wrote:

> i want to know how to configure nginx for different rails app under  
> the same domain.

You seem to have accomplished this.

> Below is my enginx configuration .i want to know where iam goin wrong  
> as i’m able to go in my home page but not able to navigate from login  
> and signup pages.

> ```
> location /app1/ {
> proxy_pass http://mongrel_cluster/;
> 
> ```

Try removing the trailing slash on this line.

Cliff

---

<div class="post-metadata">

**Author:** ![archana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@archana](https://www.ruby-forum.com/u/archana)\
**Post date:** [November 21, 2007, 9:31am UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861/3 "2007-11-21T09:31:04Z")

</div>

On Wed, Nov 21, 2007 at 08:10:44AM +0100, Archana Balaji wrote:

> i want to know how to configure nginx for different rails app under the  
> same domain.  
> for example:  
> 1)Rails application 1 [http://mydomain.com/app1](http://mydomain.com/app1)  
> 2)Rails application 2 [http://mydomain.com/app2](http://mydomain.com/app2)
> 
> Below is my enginx configuration .i want to know where iam goin wrong  
> as i’m able to go in my home page but not able to navigate from login  
> and signup pages.

How these pages (home, login, and signup) are looked from rails side ?  
What their URLs ?

---

<div class="post-metadata">

**Author:** ![archana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@archana](https://www.ruby-forum.com/u/archana)\
**Post date:** [November 24, 2007, 9:41am UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861/4 "2007-11-24T09:41:19Z")

</div>

Igor S. wrote:

> On Wed, Nov 21, 2007 at 08:10:44AM +0100, Archana Balaji wrote:
> 
> > i want to know how to configure nginx for different rails app under the  
> > same domain.  
> > for example:  
> > 1)Rails application 1 [http://mydomain.com/app1](http://mydomain.com/app1)  
> > 2)Rails application 2 [http://mydomain.com/app2](http://mydomain.com/app2)
> > 
> > Below is my enginx configuration .i want to know where iam goin wrong  
> > as i’m able to go in my home page but not able to navigate from login  
> > and signup pages.
> 
> How these pages (home, login, and signup) are looked from rails side ?  
> What their URLs ?

the url’s are redirected to main/home in the rails apps side…

The problem now is that

The things which are redirected to main /home gets directed to

[http://domain.com/main/home](http://domain.com/main/home)

I want it to be redirected to

[http://domain.com/app1/](http://domain.com/app1/)

how do i redirect it using nginx???

---

<div class="post-metadata">

**Author:** ![archana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@archana](https://www.ruby-forum.com/u/archana)\
**Post date:** [November 24, 2007, 10:05am UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861/5 "2007-11-24T10:05:59Z")

</div>

On Sat, Nov 24, 2007 at 09:41:19AM +0100, amith amith wrote:

> > > as i’m able to go in my home page but not able to navigate from login
> 
> [http://domain.com/main/home](http://domain.com/main/home)
> 
> I want it to be redirected to
> 
> [http://domain.com/app1/](http://domain.com/app1/)
> 
> how do i redirect it using nginx???

I do not understand the question.  
I do not know typical rails URLs.  
Could you write how should the URLs be mapped ?  
For example,

```
   outside world: Rails:

 domain.com/app1/ > www.domain.com/main/home
 domain.com/app1/login > www.domain.com/main/login

 domain.com/app2/ > www.domain.com/main2/home

 domain.com/app3/ > www.domain.com/main3/home

```

---

<div class="post-metadata">

**Author:** ![archana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@archana](https://www.ruby-forum.com/u/archana)\
**Post date:** [November 25, 2007, 6:15pm UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861/6 "2007-11-25T18:15:14Z")

</div>

Igor S. wrote:

> On Sat, Nov 24, 2007 at 09:41:19AM +0100, amith amith wrote:
> 
> > > > as i’m able to go in my home page but not able to navigate from login
> > 
> > [http://domain.com/main/home](http://domain.com/main/home)
> > 
> > I want it to be redirected to
> > 
> > [http://domain.com/app1/](http://domain.com/app1/)
> > 
> > how do i redirect it using nginx???
> 
> I do not understand the question.  
> I do not know typical rails URLs.  
> Could you write how should the URLs be mapped ?  
> For example,
> 
> ```
> outside world: Rails:
> 
> domain.com/app1/ > www.domain.com/main/home
> domain.com/app1/login > www.domain.com/main/login
> 
> domain.com/app2/ > www.domain.com/main2/home
> 
> domain.com/app3/ > www.domain.com/main3/home
> 
> ```

the redirecting should be as follows:

outside world: Rails:

[domain.com/app1/](http://domain.com/app1/) \> [www.domain.com/app1/main/home](http://www.domain.com/app1/main/home)  
[domain.com/app1/account/login](http://domain.com/app1/account/login) \>  
[www.domain.com/app1/account/login](http://www.domain.com/app1/account/login)  
after logging in should be redirected to \> [www.domain.com/app1/](http://www.domain.com/app1/)

[domain.com/app2](http://domain.com/app2) \> [www.domain.com/app2/main/home](http://www.domain.com/app2/main/home)

[domain.com/app3](http://domain.com/app3) \> [www.domain.com/app3/main/home](http://www.domain.com/app3/main/home)

i hope u’r able to understand from the above example.

---

<div class="post-metadata">

**Author:** ![archana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@archana](https://www.ruby-forum.com/u/archana)\
**Post date:** [February 22, 2008, 10:08pm UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861/7 "2008-02-22T22:08:05Z")

</div>

Brandon H. wrote:

> I am having the same exact issue that you describe… did you ever  
> figure out a solution?

Figured this out from another post…  
you have to use the prefix option for mongrel which can be called on the  
command line of included in the .yaml file in /etc/mongrel (if you have  
it configured that way)

See: [http://mongrel.rubyforge.org/wiki/FAQ](http://mongrel.rubyforge.org/wiki/FAQ)

---

<div class="post-metadata">

**Author:** ![archana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@archana](https://www.ruby-forum.com/u/archana)\
**Post date:** [February 22, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/configuring-nginx-for-different-rails-apps-under-same-domain/120861/8 "2008-02-22T21:45:23Z")

</div>

I am having the same exact issue that you describe… did you ever  
figure out a solution?
