Hosting a website on a Virtual Private Server (VPS) without a control panel can be challenging, but it’s easier than it looks. In this guide, we’ll show you how to host a website on a VPS using Nginx, step by step, without needing a control panel.

Nginx is a lightweight, high-performance web server. It’s an excellent choice for hosting websites because it’s easy to configure, handles high traffic efficiently, and uses fewer resources compared to other servers like Apache.
Note: This guide is performed on Ubuntu, one of the most popular Linux distributions. The steps and commands provided are specific to Ubuntu-based systems. If you’re using another Linux distribution, you must change the package installation commands.
Let’s get started with the process.
Make sure you have a ready VPS before you start. You don’t have to get your VPS from anyone in particular.
Once your VPS is set up, you need to connect to it using SSH. Open a terminal on your local machine and run the following command to access your VPS.
ssh root@your_vps_ip
Replace your_vps_ip with your VPS’s actual IP address.
To keep your server secure and up-to-date, you should update it before installing any software
Run the following commands to update your package list:
sudo apt update && sudo apt upgrade -y

Now, install Nginx and other essential tools like curl and git:
sudo apt install nginx curl git -y

If you have a domain name, you need to point it to your VPS IP address. The easiest method is to add an ‘A record’ that points to your VPS IP in your domain registrar control panel.
For example:
If you don’t have a domain, you can access your website using your server’s IP address.
Now that Nginx is installed let’s create a directory for your website’s files.
sudo mkdir -p /var/www/yourdomain.com/html

Replace yourdomain.com with your domain name.
Next, set the proper permissions for the directory:
sudo chown -R $USER:$USER /var/www/yourdomain.com/html
sudo chmod -R 755 /var/www/yourdomain.com

Create a simple index file to test:
nano /var/www/yourdomain.com/html/index.html
Add the following content to the file:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Your Website</title>
</head>
<body>
<h1>Success! Your website is hosted on Nginx.</h1>
</body>
</html>

(CTRL + X, then Y) To save and close the file.
Nginx needs to know about your website. To do this, create a configuration file for your website.
sudo nano /etc/nginx/sites-available/yourdomain.com
In the file, paste the following configuration:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}

Replace yourdomain.com with your actual domain.
Now, enable this configuration by creating a symbolic link to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/

Make sure there are no errors while testing the Ngnix configuration:
sudo nginx -t

If everything is okay, restart Nginx to apply the changes:
sudo systemctl restart nginx

Configure a firewall to allow traffic(HTTP and HTTPS) to your server.
If you’re using ufw (Uncomplicated Firewall), run the following commands:
sudo ufw allow 'Nginx Full'

This action opens the required ports: 80 for HTTP and 443 for HTTPS.
Secure your website with SSL. You can use Let’s Encrypt, a free SSL certificate provider.
First, install the certbot tool for Nginx:
sudo apt install certbot python3-certbot-nginx -y

Then, run the following command to obtain and install an SSL certificate:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Certbot will automatically configure Nginx to redirect all traffic to HTTPS.
To ensure the certificate automatically renews, add the following to your crontab:
sudo crontab -e
Then add this line:
0 3 * * * /usr/bin/certbot renew --quiet

This process automatically renews your SSL certificate every three months.
Now, if you go to your domain (or your VPS IP if you don’t have a domain), you should see the “Success!” message you added in the index.html file.
Example:
http://yourdomain.com

If everything worked correctly, congratulations! You’ve just hosted a website on your VPS using Nginx without a control panel.
Replace the test index.html with your actual website files. You can upload your website files using tools like scp (Secure Copy) or an FTP client like FileZilla.
To upload using scp, use this command from your local machine:
scp -r /path/to/your/website/files/ root@your_vps_ip:/var/www/yourdomain.com/html/

Make sure you replace /path/to/your/website/files/ with the actual path to your website files.
Congratulations, you’ve successfully created a website on your VPS using Nginx without a control panel. This method gives you more control of your server and is cheap because you don’t pay for a control panel.
If you encounter any issues, double-verify the configuration files and ensure that Nginx is properly installed and running. Enjoy your newly hosted website!

Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.