Get 50% Discount Offer 26 Days

Recommended Services
Supported Scripts
WordPress
Hubspot
Joomla
Drupal
Wix
Shopify
Magento
Typeo3
How to Host a Website on VPS Without Control Panel Using Nginx: A Step-by-Step Guide

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.

Host a Website on VPS Without Control Panel Using Nginx

Why Use Nginx for Hosting?

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.

Step 1: Set Up Your VPS

Make sure you have a ready VPS before you start. You don’t have to get your VPS from anyone in particular.

Access Your VPS

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.

Step 2: Update and Install Required Packages

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
Update and Install Required Packages

Now, install Nginx and other essential tools like curl and git:

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

Step 3: Configure Your Domain Name

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:

  • Type: A
  • Name: @ (or leave it empty)
  • Value: your_vps_ip

If you don’t have a domain, you can access your website using your server’s IP address.

Step 4: Create a Website Directory

Now that Nginx is installed let’s create a directory for your website’s files.

sudo mkdir -p /var/www/yourdomain.com/html
create a directory for your website files to host a website

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
set the proper permissions for the directory

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>
Create a simple index file to test

(CTRL + X, then Y) To save and close the file.

Step 5: Configure Nginx for Your Website

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;
    }
}
Configure Nginx for Your Website

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/
enable this configuration by creating a symbolic link

Make sure there are no errors while testing the Ngnix configuration:

sudo nginx -t
Test the Nginx configuration to make sure there are no errors

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

sudo systemctl restart nginx
restart Nginx to apply the changes

Step 6: Set Up Firewall Rules

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'
Set Up Firewall Rules

This action opens the required ports: 80 for HTTP and 443 for HTTPS.

Step 7: Secure Your Website with SSL for free using Let’s Encrypt (Optional but Recommended)

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
Secure Your Website with SSL for free using Let’s Encrypt

Then, run the following command to obtain and install an SSL certificate:

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

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 linux command will ensure the certificate automatically renews

This process automatically renews your SSL certificate every three months.

Step 8: Access Your Website

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
Access Your Website To Check if You Get Successful Message

If everything worked correctly, congratulations! You’ve just hosted a website on your VPS using Nginx without a control panel.

Step 9: Uploading Your Actual Website Files

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/
Uploading Your Actual Website Files

Make sure you replace /path/to/your/website/files/ with the actual path to your website files.

Conclusion

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!

About the writer

Vinayak Baranwal Article Author

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Lifetime Solutions:

VPS SSD

Lifetime Hosting

Lifetime Dedicated Servers