How to configure NGINX properly for 2 different sites?

128 Views Asked by At

I am setting up new server, its all done. First site works without problems.

Path is:

/var/www/html

Second site is still not avaliable, but when i ping from command line it says its online.

Multiple directories should looks like this:

/var/www/html/1 

/var/www/html/2

or something else?

At this moment my default.conf from:

/etc/nginx/sites-enabled

looks like:

server {
listen 80;
server_name example.com;
root /var/www/html;
index index.html;
}

if i want put multiple sites i have to make this file looks like :

server {
listen 80;
server_name example1.com;
root /var/www/html/1;
index index.html;
}
server {
listen 80;
server_name example2.com;
root /var/www/html/2;
index index.html;
}

or?

Any ideas?

1

There are 1 best solutions below

0
Aleksandar On BEST ANSWER

I assume you use a debian based system like debian or ubuntu.

I suggest to add a file like example2.com.conf to /etc/nginx/sites-available/ and link it to /etc/nginx/sites-enabled/

For example

example2.com.conf:

server {
listen 80;
server_name example2.com;
root /var/www/html/2;
index index.html;
}

ln -s /etc/nginx/sites-available/example2.com.conf /etc/nginx/sites-enabled/ systemctl restart nginx

Some more details are described on this page.

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04#server-configuration