Multiple sites on nginx and sites

For a basic nginx installation, your sites-available folder has only one file: default

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

+60
linux webserver nginx
Jul 27 '12 at 17:56
source share
3 answers

To add a different approach, you can use a separate file for each virtual domain or site that you host. You can use the default copy as a starting point for each of them and configure for each site.
Then create symbolic links in sites. This way you can host sites up and down simply by adding or removing a symbolic link and unloading the nginx reload service.

You can get an ad and use this method to redirect sites to a maintenance mode page during 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 

Please note: since only the first two entries are the only symbolic elements in sites-enabled , the third entry someOtherSite.com therefore not available.

+79
Jul 28 2018-12-12T00:
source share

If you look at nginx.conf , you will find the include directive, which includes all files from the sites-enabled directory. This directory stores symbolic links in the configuration files from sites-available so that it is convenient to turn parts of your configuration on and off.

As you can see, there is no magic in these directories.

If you want to host multiple websites, you must use several server and / or server_name . The official manuals are here: Server Names and How nginx Handles the Request .

+24
Jul 27 2018-12-12T00:
source share

You symbolize the default file from sites available for permitted sites. Then you modify the available site to include two server blocks, each with a different server name. see the following. It is assumed that you have domains called example.com and example2.com. You would also point @records to the ip address of the server on which you installed nginx.

Symlink accessible site to permitted site

 sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default 

edit the file using your chosen editor (vim for me)

 sudo vi /etc/nginx/sites-available/default 

Here is the contents of a working nginx conf if you use web applications on ports 4567 and 4568.

 server { server_name www.example.com location / { proxy_pass http://localhost:4567/; } } server { server_name www.example2.com location { proxy_pass http://localhost:4568/; } } 
+14
Oct 19 '13 at
source share



All Articles