Problem
Your sites-available folder has only one file with the default nginx installation: default
What is the purpose of the sites-available folder, and how can I utilize it to host numerous (different) websites?
Asked by Kristian
Solution #1
You can also use a different file for each virtual domain or site you’re hosting as an alternative. You can start with a copy of default and tweak it for each site. Then, in sites-enabled, build symlinks. By simply adding or removing a symlink and performing a service nginx reload, you can bring sites up and down.
You may get creative with this strategy and use it to redirect sites to a maintenance mode page while you work on your site.
As a result, the structure is as follows:
/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
Because the first two entries in sites-enabled are the only symlinked items, the third entry, someOtherSite.com, is consequently unavailable.
Answered by Carlos
Solution #2
You’ll notice an include directive in nginx.conf that includes all files from the sites-enabled directory. This directory contains symlinks to sites-available config files, making it easy to turn on and off elements of your configuration.
As you can see, these directories aren’t magical.
Use numerous server blocks and/or the server name directive if you want to host multiple websites. Official lessons can be found at: Names of servers and how nginx handles requests
Answered by VBart
Solution #3
The default file is symlinked from sites available to sites enabled. Then you add two server blocks to the accessible site, each with a different server name. Look at the following. This implies you own the domains example.com and example2.com, respectively. Your @records would also point to the IP address of the server where nginx is installed.
create a symlink from the available site to the active site
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
Use your preferred editor to edit the file (vim for me)
sudo vi /etc/nginx/sites-available/default
If you’re running web apps on ports 4567 and 4568, here is the contents of a functioning nginx conf.
server {
server_name www.example.com
location / {
proxy_pass http://localhost:4567/;
}
}
server {
server_name www.example2.com
location {
proxy_pass http://localhost:4568/;
}
}
Answered by jmontross
Post is based on https://stackoverflow.com/questions/11693135/multiple-websites-on-nginx-sites-available