no mad blog keyboard_arrow_right posts keyboard_arrow_right

Multi-domain nginx configuration

nginx is an open-source HTTP server.
Let’s say you’re running a server with nginx and you have two domains and You also have the HTML of two websites sitting at ~/web/ and ~/web/ And now, of course, you want visitors that go to to be directed to the website at ~/web/ and in an analog way for the other domain.

For this you make the sites available by creating their configuration files


server {
	listen 80;
	listen [::]:80;

	root /home/YOUR_USERNAME/web/;
	index index.html;


	location / {
		try_files $uri $uri/ =404;

Substitute all with and that’s your /etc/nginx/sites-available/

These sites are now available, but not enabled yet. The idea is to configure everything in /etc/nginx/sites-available/<file>, and to then have symbolic links in /etc/nginx/sites-enabled/ that point to the configuration files you want enabled.

So enable the sites:
sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Make sure your symbolic links work by issuing ls -l /etc/nginx/sites-enabled/ which should show

total 0
lrwxrwxrwx 1 root root 44 Mar 23 19:10 -> /etc/nginx/sites-available/
lrwxrwxrwx 1 root root 41 Mar 23 19:15 -> /etc/nginx/sites-available/

Assuming Ubuntu, restart nginx: sudo service nginx restart.

Alright, you’re good to go!