Deploying a website on a VPS (Virtual Private Server) gives you complete control over your hosting environment, better performance than shared hosting, and the flexibility to run any application stack you need. Whether you're launching a portfolio site, a web application, or an API backend, this guide walks you through every step.
Unlike managed hosting platforms that limit your options, a VPS lets you configure everything exactly as you need it. And with modern tools like VPS Commander, you don't even need deep terminal expertise to manage your server after deployment.
- How to set up a fresh VPS from scratch
- Installing and configuring Nginx as your web server
- Connecting a custom domain with DNS configuration
- Securing your site with free SSL from Let's Encrypt
- Deploying static sites, Node.js, Python, and PHP applications
Prerequisites
Before you begin deploying your website, make sure you have the following ready:
- A VPS server - Ubuntu 22.04 or 24.04 LTS recommended. Check our best VPS providers comparison to choose the right one.
- A domain name - Purchased from a registrar like Namecheap, Cloudflare, or GoDaddy
- SSH access - Your VPS IP address, username, and password or SSH key
- Your website files - Static HTML/CSS/JS, or application code ready for deployment
- Basic command line knowledge - Or use VPS Commander to manage your server visually
| Requirement | Recommended | Minimum |
|---|---|---|
| RAM | 2 GB | 1 GB |
| Storage | 50 GB SSD | 25 GB SSD |
| OS | Ubuntu 24.04 LTS | Ubuntu 22.04 LTS |
| CPU | 2 vCPU | 1 vCPU |
| Bandwidth | 2 TB/month | 1 TB/month |
Step 1: Choose and Set Up Your VPS
If you haven't already, create a VPS instance with your preferred provider. We recommend starting with Ubuntu 22.04 LTS or 24.04 LTS as they have the longest support period and the most tutorials available.
Recommended VPS Providers for Website Hosting
| Provider | Starting Price | Best For | Data Centers |
|---|---|---|---|
| DigitalOcean | $6/month | Beginners, great docs | 15 locations |
| Hetzner | $4.15/month | Budget, European users | 5 locations |
| Vultr | $6/month | Performance, global reach | 32 locations |
| Linode | $5/month | Reliability, support | 11 locations |
Once your VPS is created, note down your server's IP address, root password (or SSH key), and make sure the server is running.
Step 2: Connect via SSH and Initial Server Setup
Connect to your VPS using SSH from your local terminal:
ssh root@your_server_ip
If you're using an SSH key:
ssh -i ~/.ssh/your_key root@your_server_ip
Update the System
First, update all packages to their latest versions:
apt update && apt upgrade -y
Create a Non-Root User
Running everything as root is a security risk. Create a dedicated user:
# Create a new user
adduser deploy
# Add user to sudo group
usermod -aG sudo deploy
# Switch to the new user
su - deploy
Configure Basic Firewall
Set up UFW (Uncomplicated Firewall) to allow only necessary traffic:
# Allow SSH connections
sudo ufw allow OpenSSH
# Allow HTTP and HTTPS traffic
sudo ufw allow 'Nginx Full'
# Enable the firewall
sudo ufw enable
# Check status
sudo ufw status
Step 3: Install Nginx Web Server
Nginx is the most popular web server for VPS deployments. It's fast, lightweight, and handles high traffic efficiently.
# Install Nginx
sudo apt install nginx -y
# Start Nginx and enable it on boot
sudo systemctl start nginx
sudo systemctl enable nginx
# Verify it's running
sudo systemctl status nginx
Open your browser and navigate to your server's IP address (http://your_server_ip). You should see the default Nginx welcome page - this confirms your web server is working.
Understanding Nginx Directory Structure
/etc/nginx/nginx.conf- Main configuration file/etc/nginx/sites-available/- Server block configurations/etc/nginx/sites-enabled/- Active server blocks (symlinks)/var/www/- Default web root directory/var/log/nginx/- Access and error logs
Step 4: Configure Your Domain and DNS
To make your website accessible via a domain name instead of an IP address, you need to configure DNS records.
DNS Records You Need
| Record Type | Name | Value | Purpose |
|---|---|---|---|
| A | @ | your_server_ip | Points domain to server |
| A | www | your_server_ip | Points www subdomain |
| AAAA | @ | your_ipv6_address | IPv6 support (optional) |
Log in to your domain registrar (Namecheap, Cloudflare, GoDaddy, etc.) and add these DNS records. DNS propagation can take up to 48 hours, but usually completes within 30 minutes to a few hours.
Configure Nginx Server Block
Create a new Nginx server block for your domain:
# Create the web root directory
sudo mkdir -p /var/www/yourdomain.com/html
sudo chown -R $USER:$USER /var/www/yourdomain.com/html
# Create the Nginx server block
sudo nano /etc/nginx/sites-available/yourdomain.com
Add this configuration:
server {
listen 80;
listen [::]:80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
gzip_min_length 256;
# Cache static assets
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}
Enable the server block:
# Create symbolic link to enable the site
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
# Test Nginx configuration
sudo nginx -t
# Reload Nginx
sudo systemctl reload nginx
Step 5: Deploy Your Website Files
Option A: Upload Static Files via SCP
From your local machine, upload your website files:
# Upload a single file
scp index.html deploy@your_server_ip:/var/www/yourdomain.com/html/
# Upload an entire directory
scp -r ./dist/* deploy@your_server_ip:/var/www/yourdomain.com/html/
Option B: Clone from Git
If your code is in a Git repository:
# Install Git
sudo apt install git -y
# Clone your repository
cd /var/www/yourdomain.com/html
git clone https://github.com/yourusername/your-repo.git .
Option C: Use VPS Commander File Explorer
With VPS Commander, you can drag and drop files directly to your server through the web-based file explorer - no command line needed.
After uploading, set the correct file permissions:
# Set ownership
sudo chown -R www-data:www-data /var/www/yourdomain.com/html
# Set directory permissions
sudo find /var/www/yourdomain.com/html -type d -exec chmod 755 {} \;
# Set file permissions
sudo find /var/www/yourdomain.com/html -type f -exec chmod 644 {} \;
Visit http://yourdomain.com in your browser. Your website should now be live!
Step 6: Secure Your Site with SSL (Let's Encrypt)
HTTPS is essential for security, SEO rankings, and user trust. Let's Encrypt provides free SSL certificates.
# Install Certbot
sudo apt install certbot python3-certbot-nginx -y
# Obtain and install SSL certificate
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
# Follow the prompts:
# - Enter your email address
# - Agree to terms of service
# - Choose whether to redirect HTTP to HTTPS (recommended: yes)
Certbot automatically modifies your Nginx configuration to use SSL. It also sets up auto-renewal:
# Test auto-renewal
sudo certbot renew --dry-run
# Check the renewal timer
sudo systemctl status certbot.timer
https://yourdomain.com to verify. The SSL certificate auto-renews every 90 days, so you never have to worry about it expiring.
Step 7: Configure Firewall and Security
Make sure your firewall only allows the traffic you need:
# Check current firewall rules
sudo ufw status verbose
# The output should show:
# 22/tcp (OpenSSH) ALLOW IN Anywhere
# 80,443/tcp (Nginx Full) ALLOW IN Anywhere
For additional security measures, check our comprehensive VPS security guide.
Deploying Different Application Types
The steps above cover static websites. Here's how to deploy dynamic applications:
Deploying a Node.js Application
# Install Node.js (using NodeSource)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs -y
# Verify installation
node --version
npm --version
# Clone your application
cd /var/www/yourdomain.com
git clone https://github.com/yourusername/your-node-app.git app
cd app
# Install dependencies
npm install
# Install PM2 process manager
sudo npm install -g pm2
# Start your application with PM2
pm2 start app.js --name "my-website"
pm2 startup systemd
pm2 save
Configure Nginx as a reverse proxy for your Node.js app:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
Deploying a Python/Django Application
# Install Python and pip
sudo apt install python3 python3-pip python3-venv -y
# Create project directory
cd /var/www/yourdomain.com
git clone https://github.com/yourusername/your-django-app.git app
cd app
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
pip install gunicorn
# Collect static files
python manage.py collectstatic
# Start with Gunicorn
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
For production, create a systemd service for Gunicorn and configure Nginx to proxy to it.
Deploying a PHP Application
# Install PHP and PHP-FPM
sudo apt install php-fpm php-mysql php-xml php-mbstring php-curl -y
# Check PHP version
php --version
# PHP files go in your web root
sudo cp -r /path/to/your/php/app/* /var/www/yourdomain.com/html/
Update your Nginx configuration to handle PHP:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
| Application Type | Web Server | Process Manager | Nginx Role |
|---|---|---|---|
| Static Site | Nginx directly | None needed | Serves files |
| Node.js | Node + PM2 | PM2 | Reverse proxy |
| Python/Django | Gunicorn | systemd | Reverse proxy |
| PHP | PHP-FPM | PHP-FPM service | FastCGI proxy |
Troubleshooting Common Deployment Issues
502 Bad Gateway Error
Cause: Nginx can't connect to your application backend (Node.js, Gunicorn, PHP-FPM).
Fix:
# Check if your application is running
sudo systemctl status your-app
# Check Nginx error logs
sudo tail -f /var/log/nginx/error.log
# Verify the backend port matches Nginx config
# e.g., proxy_pass http://localhost:3000 must match your app's port
403 Forbidden Error
Cause: File permissions are incorrect.
Fix:
# Fix ownership
sudo chown -R www-data:www-data /var/www/yourdomain.com/html
# Fix permissions
sudo chmod -R 755 /var/www/yourdomain.com/html
DNS Not Resolving
Cause: DNS records haven't propagated yet, or are configured incorrectly.
Fix:
# Check DNS propagation
dig yourdomain.com +short
# Or use nslookup
nslookup yourdomain.com
# Verify A record points to your server IP
# Wait up to 48 hours for full propagation
SSL Certificate Errors
Cause: Certificate not installed properly or domain mismatch.
Fix:
# Re-run Certbot
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
# Check certificate status
sudo certbot certificates
# Force renewal
sudo certbot renew --force-renewal
Frequently Asked Questions
How much does it cost to deploy a website on a VPS?
VPS hosting starts at around $4-6/month for a basic server. Combined with a domain ($10-15/year) and free SSL from Let's Encrypt, you can host a website for under $10/month. See our VPS provider comparison for detailed pricing.
Is a VPS better than shared hosting for my website?
Yes, for most cases. A VPS gives you dedicated resources (CPU, RAM), root access, better performance, and the ability to run any software. Shared hosting is only suitable for very small, low-traffic websites.
Do I need to know Linux to deploy on a VPS?
Basic Linux knowledge helps, but tools like VPS Commander allow you to manage servers through a visual interface without terminal commands. You can deploy, manage files, and monitor your server entirely through a web browser.
How long does it take to deploy a website on a VPS?
A simple static website can be deployed in 15-30 minutes. More complex applications (Node.js, Django, etc.) may take 1-2 hours for the initial setup including SSL and domain configuration.
Can I host multiple websites on one VPS?
Absolutely! Nginx supports multiple server blocks (virtual hosts), allowing you to host many websites on a single VPS. Each site gets its own domain, directory, and configuration.
Which web server should I use: Nginx or Apache?
We recommend Nginx for most deployments. It uses less memory, handles more concurrent connections, and performs better as a reverse proxy. Apache is better if you need .htaccess file support or complex per-directory configurations.
How do I update my website after deployment?
You can use Git pull to update from your repository, SCP/SFTP to upload new files, or use VPS Commander's file explorer to drag and drop updated files. For zero-downtime updates, consider using PM2's reload feature for Node.js apps.
What if my VPS runs out of resources?
Most VPS providers allow easy vertical scaling - you can upgrade RAM, CPU, and storage with a few clicks. Monitor your resource usage with htop, df -h, and free -m to plan upgrades before hitting limits.
Conclusion
Deploying a website on a VPS is a straightforward process once you understand the steps. By following this guide, you now have a production-ready website with Nginx, SSL encryption, and proper security configuration.
The key steps to remember are:
- Set up your VPS with a secure non-root user and firewall
- Install Nginx as your web server
- Configure DNS to point your domain to your server
- Deploy your files via SCP, Git, or file manager
- Install SSL with Let's Encrypt for free HTTPS
- Secure your server with proper firewall and permissions
For ongoing server management without the terminal hassle, try VPS Commander - it provides 400+ automated workflows, visual file management, and real-time server monitoring through an intuitive web interface.