Multiple sites under same domain with one app codebase

martyparish nginx-forum at nginx.us
Fri Jul 18 13:40:43 UTC 2014


Hello nginx gurus,

First post but I have been reading this board for over a year!

My scenario:

I have many separate "sites" to run and they all use the same back end
application(opencart). They also will be under the same domain, in folders.
I don't want to duplicate the application code in each subdirectory.

I've got it working with a few sites and it works well. However, I will have
~200 sites soon.

Example sites:

domain.com/site1/
domain.com/site2/
etc...

My main code base is located at the root of domain.com.

I am currently using location rewrite blocks for each site.

That will get ugly when I have 200 sites, and a pain when I want to add new
sites.

Can anyone help me with a "dynamic" configuration so I don't have to edit
conf files each time?


===========================


server {
	listen       80;
	server_name  domain.com;
	root /etc/nginx/html/development;
	error_log /var/log/nginx/dev.error.log;
	index index.php;

	rewrite ^([^.]*[^/])$ $1/ permanent; # trailing slash
	
	# HERE IS THE CODE I WANT TO FIX
	location ^~ /site1/ {
		rewrite ^/site1/(.*) /$1; 
	}
	location ^~ /site2/ {
		rewrite ^/site2/(.*) /$1;
	}
	location ^~ /site3/ {
		rewrite ^/site3/(.*) /$1; 
	}

}

=============================

Could I use map module, or possibly a single location regex?


Thanks!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,251908,251908#msg-251908



More information about the nginx mailing list