# Nginx virtual hosts + mongrel cluster +strange problem

**URL:** <https://www.ruby-forum.com/t/nginx-virtual-hosts-mongrel-cluster-strange-problem/153863>\
**Category:** NGINX\
**Created:** [November 21, 2008, 11:04pm UTC](https://www.ruby-forum.com/t/nginx-virtual-hosts-mongrel-cluster-strange-problem/153863 "2008-11-21T23:04:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alpagas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@alpagas](https://www.ruby-forum.com/u/alpagas)\
**Post date:** [November 21, 2008, 11:04pm UTC](https://www.ruby-forum.com/t/nginx-virtual-hosts-mongrel-cluster-strange-problem/153863/1 "2008-11-21T23:04:48Z")

</div>

hi all!

I have a dedicated host for my web application  
I want to run 2 rails applications with the following adress

[http://www.8ansapres.fr](http://www.8ansapres.fr) and  
[http://blog.8ansapres.fr](http://blog.8ansapres.fr)

on my server applications have the following path  
/home/alpaga/8ansapres.fr/current/  
/home/alpaga/blog.8ansapres.fr/

my nginx.conf look like this

user alpaga;

worker\_processes 4;

pid /var/run/nginx.pid;

events {  
worker\_connections 8192;  
use epoll; # linux only!  
}

http {

include /etc/nginx/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 /var/log/nginx/access.log main;

error\_log /var/log/nginx/error.log notice;

sendfile on;

tcp\_nopush on;  
tcp\_nodelay on;

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;

include /etc/nginx/sites-enabled/\*;  
}

my first virtual host:

# Load balance to mongrels

upstream mongrel\_cluster {  
server 127.0.0.1:8000;  
server 127.0.0.1:8001;  
server 127.0.0.1:8002;  
}

# Begin virtual host configuration

server {

# Familiar HTTP settings

listen 80;  
server\_name [www.8ansapres.fr](http://www.8ansapres.fr);  
root /home/alpaga/8ansapres.fr/current/public;  
access\_log /var/log/nginx/8ansapres.fr.access.log;  
error\_page 500 502 503 504 /500.html;  
client\_max\_body\_size 50M;

# First rewrite rule for handling maintenance page

if (-f $document\_root/system/maintenance.html) {  
rewrite ^(.\*)$ /system/maintenance.html last;  
break;  
}

location / {  
index index.html index.htm;  
# Forward information about the client and host  
# Otherwise our Rails app wouldn’t have access to it  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_max\_temp\_file\_size 0;  
# Directly serve static content  
location ~ ^/(images|javascripts|stylesheets)/ {  
expires 10y;  
}  
if (-f $request\_filename) {  
break;  
}  
# Directly serve cached pages  
if (-f $request\_filename.html) {  
rewrite (.\*) $1.html break;  
}  
# Otherwise let Mongrel handle the request  
if (!-f $request\_filename) {  
proxy\_pass http://mongrel\_cluster;  
break;  
}  
}  
}

my second virtual host:

# Load balance to mongrels

upstream mongrel\_cluster\_two {  
server 0.0.0.0:8000;  
server 0.0.0.0:8001;  
server 0.0.0.0:8002;  
}

# Begin virtual host configuration

server {

# Familiar HTTP settings

listen 80;  
server\_name [blog.8ansapres.fr](http://blog.8ansapres.fr);  
root /home/alpaga/blog.8ansapres.fr/public;  
access\_log /var/log/nginx/blog.8ansapres.fr.access.log;  
error\_page 500 502 503 504 /500.html;  
client\_max\_body\_size 50M;

# First rewrite rule for handling maintenance page

if (-f $document\_root/system/maintenance.html) {  
rewrite ^(.\*)$ /system/maintenance.html last;  
break;  
}

location / {  
index index.html index.htm;  
# Forward information about the client and host  
# Otherwise our Rails app wouldn’t have access to it  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_max\_temp\_file\_size 0;  
# Directly serve static content  
location ~ ^/(images|javascripts|stylesheets)/ {  
expires 10y;  
}  
if (-f $request\_filename) {  
break;  
}  
# Directly serve cached pages  
if (-f $request\_filename.html) {  
rewrite (.\*) $1.html break;  
}  
# Otherwise let Mongrel handle the request  
if (!-f $request\_filename) {  
proxy\_pass http://mongrel\_cluster\_two;  
break;  
}  
}  
}

my mongrel\_cluster files

application 1

port: “8000”  
pid\_file: tmp/pids/mongrel.pid  
servers: 3  
cwd: /home/alpaga/8ansapres.fr/current/  
log\_file: log/mongrel.log  
environment: production  
address: 127.0.0.1  
servers: 3  
docroot: public

application 2

port: “8003”  
pid\_file: tmp/pids/mongrel.pid  
servers: 3  
cwd: /home/alpaga/blog.8ansapres.fr/  
log\_file: log/mongrel.log  
environment: production

address: 0.0.0.0  
servers: 3  
docroot: public

the first application ([8ansapres.fr](http://8ansapres.fr)) run very well but i can’t access  
the second one.  
However, I can access the second application with  
[http://www.8ansapres.fr:8003/](http://www.8ansapres.fr:8003/)

I did many tests and it’s seems I cant’ access to  
[http://blog.8ansapres.fr/](http://blog.8ansapres.fr/)

I really don’t know were I’am wrong

Do I have to add the subdomain with the registar or something like this  
?

thank you very much for your help

the error.log is blank and in blog.8ansapres.fr.access.log i have :

80.96.123.27 - - [21/Nov/2008:22:55:06 +0100] “GET  
/w00tw00t.at.ISC.SANS.DFind:) HTTP/1.1” 400 173 “-” “-”  
80.96.121.241 - - [21/Nov/2008:22:56:09 +0100] “GET  
/w00tw00t.at.ISC.SANS.DFind:) HTTP/1.1” 400 173 “-” “-”

---

<div class="post-metadata">

**Author:** ![alpagas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@alpagas](https://www.ruby-forum.com/u/alpagas)\
**Post date:** [November 28, 2008, 7:54pm UTC](https://www.ruby-forum.com/t/nginx-virtual-hosts-mongrel-cluster-strange-problem/153863/2 "2008-11-28T19:54:43Z")

</div>

Sorry about the late reply. Did you fix it?

Try changing:

# Load balance to mongrels

upstream mongrel\_cluster\_two {  
server 0.0.0.0:8000;  
server 0.0.0.0:8001;  
server 0.0.0.0:8002;  
}

to

# Load balance to mongrels

upstream mongrel\_cluster\_two {  
server 0.0.0.0:8003;  
server 0.0.0.0:8004;  
server 0.0.0.0:8005;  
}

---

<div class="post-metadata">

**Author:** ![alpagas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@alpagas](https://www.ruby-forum.com/u/alpagas)\
**Post date:** [November 30, 2008, 11:29pm UTC](https://www.ruby-forum.com/t/nginx-virtual-hosts-mongrel-cluster-strange-problem/153863/3 "2008-11-30T23:29:23Z")

</div>

Excellent !!! it works, thanks you very much Dom !
