I'm somewhat confused about using Nginx and Thin for serving my Rails
3.2 app. Previously I had Thin serving my Rails app on Windows Server
2008 R2 without any issues. I would start Thin on the production server
specifying the server's IP address on port 80 like such:
rails server thin -b 10.xx.x.xxx -p 80 -e production
Now, I'm trying to add Nginx to the mix and I'm confused about how I
should start Thin and how I should configure Nginx to forward to Thin.
For example, now that Nginx is listening on port 80, should I start Thin
locally on a different port? Like 0.0.0.0:3000 (or 127.0.0.1:3000)? Or
do I start Thin like I did before on 10.xx.x.xxx:80?
In my Nginx conf file do I specify the upstream servers as localhosts,
or the machine's IP address? I'm not really sure what it's for.
upstream mywebapp_thin {
server 0.0.0.0:3000;
}
server {
listen 80;
server_name mywebserver www.mywebserver;
# locations et. al. excluded for brevity...
Most examples I see have the upstream servers running on ports 3000 or
5000. I'm wondering if those examples are really for a development
setup, and not production? Or does Thin need to run on a different port
other than 80 since Nginx is listening on it now?
I noticed that my web app does not respond to the basic urls
(mywebserver/projects) unless I add the port Thin is running on
(mywebserver:3000/projects)
StackOverflow link:
http://stackoverflow.com/questions/11849827/nginx-...
on 2012-08-08 21:46
on 2012-08-09 01:41
On Wed, Aug 08, 2012 at 09:46:31PM +0200, Edward Stembler wrote: Hi there, > Now, I'm trying to add Nginx to the mix and I'm confused about how I > should start Thin and how I should configure Nginx to forward to Thin. If you have nginx listening on port 80, you should put Thin listening on another port. It is probably best to put it listening on an address like 127.0.0.1. > In my Nginx conf file do I specify the upstream servers as localhosts, > or the machine's IP address? I'm not really sure what it's for. The upstream is whatever Thin is listening on, and should include a specific address, not 0.0.0.0. (The "upstream" configuration does nothing until it is referenced in the proxy_pass directive which follows.) > upstream mywebapp_thin { > server 0.0.0.0:3000; > } > > server { > listen 80; > server_name mywebserver www.mywebserver; > # locations et. al. excluded for brevity... The important location{} block is the one that refers to all urls that should be handled by Thin (and refers to no urls that should not be handled by Thin). In that location{}, you will want something like proxy_pass http://mywebapp_thin; or maybe proxy_pass http://mywebapp_thin/; Depending on how Thin responds, you may also want some proxy_set_header lines. http://nginx.org/r/location http://nginx.org/r/proxy_pass http://nginx.org/r/proxy_set_header Good luck with it, f -- Francis Daly francis@daoine.org
on 2012-08-09 16:07
Thanks, that helps!
I finally got it working. I started Thin on port 8080, and removed the
upstream block while only referencing Thin in a location block
location / {
try_files $uri/index.html $uri.html $uri @mywebapp_thin;
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
error_page 403 /403.html;
}
location @mywebapp_thin {
proxy_pass http://10.x.x.x:8080;
}
This seems to work. Thanks for explaining things!
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.