This guide will walk you through setting up a web server using NGINX or Apache2 on Ubuntu, including the configuration of custom virtual hosts. Do not attempt to install both Webserver software

Requirements

  • Domain setup with an A record pointed to the VPS IP-Adres.

Setting Up NGINX

Install NGINX

  • Update the package lists: sudo apt update

  • Install NGINX: sudo apt install nginx

Configure Virtual Hosts

  • Create a directory for your website: sudo mkdir -p /var/www/your_domain/html

  • Assign ownership: sudo chown -R $USER:$USER /var/www/your_domain/html

  • Create a configuration file: sudo nano /etc/nginx/sites-available/your_domain

  • Add server block configuration in the file. Replace 'your_domain' with your actual domain name.

  • Enable the file by creating a link to the sites-enabled directory: sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

  • Test configuration: sudo nginx -t

  • Reload NGINX: sudo systemctl reload nginx

Setting Up Apache2

Install Apache2

  • Update your package lists: sudo apt update

  • Install Apache2: sudo apt install apache2

Configure Virtual Hosts

  • Create a directory for your site: sudo mkdir -p /var/www/your_domain

  • Grant permissions: sudo chown -R $USER:$USER /var/www/your_domain

  • Create a virtual host file: sudo nano /etc/apache2/sites-available/your_domain.conf

  • Add the virtual host configuration. Be sure to replace 'your_domain' with your actual domain.

  • Enable the new site: sudo a2ensite your_domain.conf

  • Disable the default site: sudo a2dissite 000-default.conf

  • Test for configuration errors: sudo apache2ctl configtest

  • Reload Apache2: sudo systemctl reload apache2

Conclusion

Setting up NGINX or Apache2 with custom virtual hosts on Ubuntu allows you to host multiple websites on a single server. Ensure you replace 'your_domain' with your actual domain name and configure your DNS settings accordingly for your domains to be accessible on the internet.

Was this answer helpful? 0 Users Found This Useful (0 Votes)