close, but you don’t have to run an HAproxy
What Nginx runs to identify servers is the server_name declaration.
I have a good example of this running on an ubuntu desktop machine that has nginx web pages and webmin. The nginx web I use as my proxy controller by redirection. The way the server works is by name. Usually a copy of bind9 is loaded on the machine, but I forgo that because I have control over rebooting the ipfire instance to force arp/ hostname updates.
Ok, my ipfire domain is .sdak So I wanted a http web at my static assigned green server at 10.65.64.190 on my network that I am going to assign it the address ubuntu.sdak. I also have a webmin Perl/GCI on port 10000 on the same computer that I’m going to host it as webmin.sdak.
So in my default file in the sites-available folder, I have:
server {
listen 80;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name ubuntu.sdak;
location / {
try_files $uri $uri/ =404;
}
}
I also created a file named webmin in this folder
server {
listen 80;
listen 443;
server_name webmin.sdak;
root /var/www/webmin;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
then I open a terminal and link the webmin site data to sites-enable:
sudo ln -s sites-available/webmin sites-enabled/
Then I navigate to /var/www and copy the folder of ubuntu site as webmin folder
sudo cp -r /var/www/html /var/www/webmin
Then I go to the new webmin folder, and rename the index file from the sample default file…
cd /var/www/webmin
mv index.nginx-debian.html index.html
Then I edit index.html and put my port redirect
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=https://10.65.64.190:10000/" />
</head>
<body>
Should redirect
</body>
</html>
Then in ipfire I set hosts on the same ip of 10.65.64.190:
Reboot ipfire and green server.
Then I clear history on a browser on the computer and navigate to either http://webmin.sdak or https://webmin.sdak or http://ubuntu and they go to the correct pages.
The reason why this works is nginx looks at the http/https request and parses the name that points to the server entries.
Same thing as 2 websites, I am just using one as a redirect to a cgi/perl instance instead of continuing at /var/www/webmin. The important thing to do is create the symbol link from sites-available to sites-enabled or the second site will not be active.
If I wanted to add more websites, I would make a new serverlet file in etc/nginx/sites-available, link it to sites-enable, and add the name in “Network => Edit Hosts” inside ipfire to the same ip address on green.