# Setting up nginx as reverse proxy for a mongrel\_cluster

**URL:** <https://www.ruby-forum.com/t/setting-up-nginx-as-reverse-proxy-for-a-mongrel-cluster/164466>\
**Category:** Deployment\
**Created:** [April 1, 2009, 6:27pm UTC](https://www.ruby-forum.com/t/setting-up-nginx-as-reverse-proxy-for-a-mongrel-cluster/164466 "2009-04-01T18:27:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![balint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@balint](https://www.ruby-forum.com/u/balint)\
**Post date:** [April 1, 2009, 6:27pm UTC](https://www.ruby-forum.com/t/setting-up-nginx-as-reverse-proxy-for-a-mongrel-cluster/164466/1 "2009-04-01T18:27:39Z")

</div>

Hi,

I have a nginx set up to reverse proxy to a mongrel\_cluster. The  
relevant part of the nginx config is below:

upstream mongrel {  
server 127.0.0.1:8000;  
server 127.0.0.1:8001;  
server 127.0.0.1:8002;  
}  
server {  
(…)  
if (!-f $request\_filename) {  
proxy\_pass [http://mongrel](http://mongrel);  
break;  
}  
}

And the config of the mongrel cluster:

* * *

user: mongrel  
cwd: /opt/sites/xxx  
log\_file: log/mongrel.log  
port: “8000”  
environment: production  
group: mongrel

# address: 127.0.0.0

pid\_file: tmp/pids/mongrel.pid  
servers: 3

I start the mongrel\_cluster with “sudo -u mongrel mongrel\_rails  
cluster::start”

The above setup works. However, what I would like to achieve is the to  
have the mongrel\_cluster only available through the rev. proxy (so  
[http://example.com:8000](http://example.com:8000) will not work, only [http://example.com](http://example.com)). For  
that I’d have to uncomment the above address: 127.0.0.0 line.

When I do that, I get an 502 accessing [http://example.com](http://example.com) and I am not  
sure why. Also, all the nginx error logs are empty so I can not peek  
into the problem. (I got the 502 from the access log). The entire config  
files are here: [http://gist.github.com/88662](http://gist.github.com/88662)

Any help is appreciated,  
Balint

---

<div class="post-metadata">

**Author:** ![balint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@balint](https://www.ruby-forum.com/u/balint)\
**Post date:** [July 11, 2009, 8:26am UTC](https://www.ruby-forum.com/t/setting-up-nginx-as-reverse-proxy-for-a-mongrel-cluster/164466/2 "2009-07-11T08:26:55Z")

</div>

I am not sure if I understand your question 100% but if what i  
understood correct then you need to restart the nginx service. once this  
is done, you should be able to see the correct site [example.com](http://example.com) without  
the :8000

---

<div class="post-metadata">

**Author:** ![balint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@balint](https://www.ruby-forum.com/u/balint)\
**Post date:** [July 11, 2009, 11:59am UTC](https://www.ruby-forum.com/t/setting-up-nginx-as-reverse-proxy-for-a-mongrel-cluster/164466/3 "2009-07-11T11:59:55Z")

</div>

Quee Mm wrote:

> I am not sure if I understand your question 100% but if what i  
> understood correct then you need to restart the nginx service. once this  
> is done, you should be able to see the correct site [example.com](http://example.com) without  
> the :8000

Maybe I was not clear. I would like the site _not_ to be available  
through the port numberered URL. So I would like [http://example.com:8000](http://example.com:8000)  
to be rejected and [http://example.com](http://example.com) to work.

It is not a big thing after all but it is kind of elegant to have the  
:8000 version closed down.

Thank you for your help,  
BÃ¡lint
