Welcome! Log In Create A New Profile

Advanced

"Correct" way of configuring multiple vhosts?

Posted by edflecko 
"Correct" way of configuring multiple vhosts?
November 01, 2022 04:11PM
I have compiled Nginx from source and installed it on an Ubuntu 22.04 virtual machine. I have assigned multiple IP addresses to the virtual machine NIC - 192.168.1.180-185.

To bypass the need for DNS, I have added the following entries to my local hosts file:

127.0.0.1 alpine.com
127.0.0.1 www.alpine.com
127.0.0.1 contoso.com
127.0.0.1 www.contoso.com
127.0.0.1 northwind.com
127.0.0.1 www.northwind.com

In the configuration file for the fictitious "alpine.com" website, my server block looks like:

server {
listen 80;
listen [::]:80;
root /usr/share/nginx/html/alpine.com/;
server_name alpine.com www.alpine.com;
index index.html index.htm index.php;
...

I have included a basic .html page in the site root for testing.

When I launch the browser within the VM, and try to go to: alpine.com, I get the Nginx default webpage and not the test webpage for alpine.com.

I don't understand why this is happening and this behavior is probably part of my larger question which is...

What IS the "correct" way of setting up multiple server blocks (i.e., virtual hosts) on Nginx in a production environment? Since I have multiple IP addresses available, is the correct way of setup to change this:

server {
listen 80;

to this:

server {
listen 192.168.1.181:80;

Since "server_name" IS specified, shouldn't that be enough for Nginx to find/display the correct site without having to specify the IP address as well?

Comments? Suggestions? Thank you!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 72
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready