Welcome! Log In Create A New Profile


"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 -

To bypass the need for DNS, I have added the following entries to my local hosts file: alpine.com www.alpine.com contoso.com www.contoso.com northwind.com 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 {

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: 263
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready