Run a business? Check out LessAccounting, our bookkeeping system that'll save you hours per week.

Announcing:

We built the entrepreneur's bookkeeping system, it's called LessAccounting. You'll probably love it.

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

written by Steven on March 25, 2007

This happened a bit ago, and I am only now finding the time to blog it. Ezra's 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;
worker_processes  6;
error_log  logs/error.log  debug;
pid        logs/nginx.pid;
events {
	worker_connections  1024;
}
http {
	include       conf/mime.types;
	default_type  application/octet-stream;
.......

	upstream mongrel_site_one {
		server 127.0.0.1:15001;
		server 127.0.0.1:15002;
	}
	server {
		listen			real_ip_number:80;
		root			/rails/site_one/current/public;
		server_name	  www.site_one.com site_one.com;
         ........
			if (!-f $request_filename) {
			proxy_pass http://mongrel_site_one;
				break;
			}
         } #server


	upstream mongrel_site_two {
		server 127.0.0.1:15003;
		server 127.0.0.1:15004;
	}
	server {
		listen			real_ip_number:80;
		root			/rails/site_two/current/public;
		server_name	  www.site_two.com site_two.com;
         ........
			if (!-f $request_filename) {
			proxy_pass http://mongrel_site_two;
				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.

Business Owners: save hours per week with LessAccounting. It's like Quickbooks, just not total shit.

1 Comment

MTecknology
MTecknology said on January 10, 2012

http://wiki.nginx.org/IfIsEvil && http://wiki.nginx.org/Pitfalls

Don’t use an if. There’s 100% zero reason to use it in your example.

Leave a Comment

About Steven
Steven Bristol has written code for the past 20 years. He like green vegetables and kittens, oh and butterflies too. He loves to throw ninja stars at his enemies.

You Should...

Follow Steven on Twitter
Friend Steven on Facebook
Subscribe
LessEverything Copyright 2011 LessEverything.com
We don't like footers, they're kinda boring