Hello Rails experts. I’m trying to set up Nginx with Mongrel cluster for
my Rails app. I got Nginx and Mongrel cluster to each work. I got Nginx
to serve static files no problem. It displays the Rails intro page, for
example.
And I got Mongrel cluster to run, and when I check each of the nodes
individually it is serving the dynamic Rails pages as expected.
However, when I start them both and then try to access my app, I get the
error “Bad Gateway”.
In the Nginx error log I find each attempt produces three entries like
this…
- 2007/09/18 06:53:13 [error] 156690: *1 connect() failed (111:
Connection refused) while reading response header from upstream, client:
24.143.132.67, server: www.joehost.com, URL: “/journal”, upstream:
“http://127.0.0.1:3000/journal”, host: “joehost.com” - 2007/09/18 06:53:13 [error] 156690: *1 connect() failed (111:
Connection refused) while reading response header from upstream, client:
24.143.132.67, server: www.joehost.com, URL: “/journal”, upstream:
“http://127.0.0.1:3001/journal”, host: “joehost.com” - 2007/09/18 06:53:13 [error] 156690: *1 connect() failed (111:
Connection refused) while reading response header from upstream, client:
24.143.132.67, server: www.joehost.com, URL: “/journal”, upstream:
“http://127.0.0.1:3002/journal”, host: “joehost.com”
My Nginx config file contains…
upstream mongrel {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
server 127.0.0.1:3002;
}
server {
listen 80;
client_max_body_size 1M;
server_name joehost.com;
root /home/joe/www/public;
access_log logs/nginx.joe.access.log main;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
location / {
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_redirect false;
proxy_max_temp_file_size 0;
if (-f $request_filename) {
break;
}
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://mongrel;
break;
}
}
Any help would be greatly appreciated.