One last thing about nginx -- how to config many sites

Written by on Mar 25 2007

This happened a bit ago, and I am only now finding the time to blog it. Ezra’s blog example wasn’t quite clear regarding how to set up nginx for multiple sites, so I asked him. It was perfectly clear after he answered that each site or port needs it’s own upstream and server directives:

user blah; workerprocesses 6; errorlog logs/error.log debug; pid logs/nginx.pid; events { workerconnections 1024; } http { include conf/mime.types; defaulttype application/octet-stream; …….

upstream mongrelsiteone { server 127.0.0.1:15001; server 127.0.0.1:15002; } server { listen realipnumber:80; root /rails/siteone/current/public; servername www.siteone.com siteone.com; …….. if (!-f $requestfilename) { proxypass http://mongrelsiteone; break; } } #server

upstream mongrelsitetwo { server 127.0.0.1:15003; server 127.0.0.1:15004; } server { listen realipnumber:80; root /rails/sitetwo/current/public; servername www.sitetwo.com sitetwo.com; …….. if (!-f $requestfilename) { proxypass http://mongrelsitetwo; break; } } #server } #http

Also note that if you are going to run ssl, you will need an extra server block for the ssl config, which listens on 443. Thanks again to Ezra for this one.

Meet
Steven

Hi I'm Steven,

I wrote the article you're reading... I lead the developers, write music, used to race motorcycles, and help clients find the right features to build on their product.

Get Blog Updates