Host multiple domains under the same server IP
How to host multiple, different domains under the same server IP using Nginx
On this page
How to host multiple, different domains under the same server IP using Nginx.
Prerequisites
- Root access to the web server to update the
nginx.conf
file. - Unique public folders for each website (i.e.
/var/www/mydomain1
,/var/www/mydomain2
)
Instructions
Log into your web server via SSH.
Edit the
/etc/nginx/nginx.conf
file and update it with 2server { }
block directives:server { listen 80; root /var/www/mydomain1; index index.html; server_name mydomain1.com; } server { listen 80; root /var/www/mydomain.com; index index.html; server_name mydomain2.com; }
Save the
nginx.conf
fileReload the configuration file to test the web server:
sudo nginx -t
Restart Nginx:
sudo systemctl restart nginx