Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple websites on nginx & sites-available

With the base install of nginx, your sites-available folder has just one file: default

how does the sites-available folder work and how would I use it to host multiple (separate) websites?

like image 789
Kristian Avatar asked Jul 27 '12 17:07

Kristian


People also ask

Can NGINX serve multiple sites?

NGINX allows you to host multiple websites on a single server with the help of virtual hosts. Each virtual host handles a website domain and serves requests from its own Document Root folder.


1 Answers

Just to add another approach, you can use a separate file for each virtual domain or site you're hosting. You can use a copy of default as a starting point for each one and customize for each site.
Then create symlinks in sites-enabled. In this way you can take sites up and down just by adding or removing a symlink and issuing a service nginx reload.

You can get creative and use this method to redirect sites to a maintenance mode page while you are doing site maintenance.

So the structure looks like this:

/sites-available/ (you can use obvious file names like this) |  |-> a.mysite.com |-> b.mysite.com |-> someOtherSite.com  /sites-enabled/ (these are just symlinks to the real files in /sites-available) |  |-> a.mysite.com |-> b.mysite.com 

Notice that since there are only the first two entries are the only symlinked items in sites-enabled, the third entry, someOtherSite.com is therefore offline.

like image 85
Carlos Avatar answered Sep 21 '22 22:09

Carlos