Question

Setup vps with nginx and add multiple website

Hi guys, i relative new to this but someone can help me configure a ubuntu 20.04 vps with nginx host multiple website please? First i want to configure it to acces ip_adress/website1 and ip_adress/website2 so i can move/duplicate the websites and then to redirect the domain too after i finish configure all. I tryed many tutorials but didn’t manage to get it done. All i have managed to do is to add website accesed when i type the ip. Thanks


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hi @rober7h,

When you install Nginx you get a default file which loads Nginx on your Droplet’s IP address. This file can be found here:

/etc/nginx/sites-enabled/

In order to add two new websites to load like - XXX.XXX.XXX.XXX/website1 and XXX.XXX.XXX.XXX/website2 where XXX.XXX.XXX.XXX is your IP address. First to make sure which is the root folder from which your file is loading files execute the following

grep root /etc/nginx/sites-enabled/default

You’ll get a result like this:

root@ubuntu-s-1vcpu-1gb-nyc1-01:/etc/nginx/sites-enabled# grep root default
        root /var/www/html;

This means your root folder is /var/www/html. In that folder create the folders for your websites like so:

root@ubuntu-s-1vcpu-1gb-nyc1-01:/etc/nginx/sites-enabled# cd /var/www/html
root@ubuntu-s-1vcpu-1gb-nyc1-01:/var/www/html# mkdir -p {website1,website2}
root@ubuntu-s-1vcpu-1gb-nyc1-01:/var/www/html# ls -lah
total 20K
drwxr-xr-x 4 root root 4.0K Apr  1 06:56 .
drwxr-xr-x 3 root root 4.0K Apr  1 06:51 ..
-rw-r--r-- 1 root root  612 Apr  1 06:51 index.nginx-debian.html
drwxr-xr-x 2 root root 4.0K Apr  1 06:56 website1
drwxr-xr-x 2 root root 4.0K Apr  1 06:56 website2
root@ubuntu-s-1vcpu-1gb-nyc1-01:/var/www/html#

Now inside those two folders create a simple index.html file like so

root@ubuntu-s-1vcpu-1gb-nyc1-01:/var/www/html# echo 'Test website1' > /var/www/html/website1/index.html
root@ubuntu-s-1vcpu-1gb-nyc1-01:/var/www/html# echo 'Test website2' > /var/www/html/website2/index.html

The above commands will just add the text ‘Test website1’ or ‘Test website2’ into an index.html file in the location /var/www/html/website[1,2]/index.html.

Now load your websites like so XXX.XXX.XXX.XXX/website1 and XXX.XXX.XXX.XXX/website2 where XXX.XXX.XXX.XXX is your IP address.

That’s it, you are ready to go.

Regards, KFSys

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @rober7h,

Once you are done with the testing and you want to make your websites load with different domains, you’ll need to add configuration files for each website in the /etc/nginx/sites-enabled/ folder.

Luckily, DigitalOcean has a pretty great tutorial on how you can do that. You can check that here:

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04

Regards, KFSys