By Robert H
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
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!
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
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.