This step-by-step guide will help you set up an affordable and straightforward VPS to host your web applications. Whether you’re hosting a single HTML file or deploying Docker containers, this approach will work.
Supported OS: Ubuntu
Choose a VPS that fits your system requirements. I generally opt for the smallest option since most providers allow you to scale up as needed.
You’ll need SSH access to interact with your server. If you’re unfamiliar with SSH, here’s a guide to get started.
Digital Ocean offers the option to deploy a Droplet with Docker pre-installed, though availability may vary across providers.
For VPS setups without Docker, follow this installation guide.
Once you’ve SSH’d into the server, update system packages and install Nginx:
sudo apt-get update
sudo apt-get install nginx
# Press Enter to restart default services
Now, remove the default Nginx configurations:
cd /etc/nginx/sites-available/ && rm default
cd /etc/nginx/sites-enabled/ && rm default
Most VPS providers offer firewall GUIs for ease of configuration. Here’s an example from Hetzner’s cloud platform.
Alternatively, you can manually set up a firewall following this guide.
This page will be displayed when your site is offline. It’s also a great way to test serving static files from your VPS.
To create a simple maintenance.html page, run:
cd && sudo mkdir /var/www/mysite.com
cd /var/www/mysite.com
sudo nano maintenance.html
Paste in your HTML content, save, and exit the editor.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Maintenance Mode</title>
<style>
body {
background-color: #f4f4f4;
font-family: Arial, sans-serif;
text-align: center;
padding: 100px;
}
.container {
max-width: 600px;
margin: auto;
padding: 20px;
background: white;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
}
h1 {
color: #333;
}
p {
font-size: 18px;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h1>🚧 Maintenance Mode 🚧</h1>
<p>We are currently working on some improvements!</p>
<p>Check back soon.</p>
</div>
</body>
</html>
Let’s assume you have a Docker container running on port 8008. We’ll configure Nginx to route traffic to this application while using the maintenance page as a fallback.
First, create an Nginx configuration file:
cd && sudo nano /etc/nginx/sites-available/mysite.com
Now, add the following:
server {
server_name mysite.com;
location / {
proxy_pass http://127.0.0.1:8008;
}
location @static {
root /var/www/mysite.com;
try_files /maintenance.html =404;
}
}
server {
listen 80;
listen [::]:80;
server_name mysite.com;
}
Activate your Nginx configuration:
cd && sudo ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/mysite.com
Verify the setup:
sudo nginx -t
If the test succeeds, restart Nginx:
sudo systemctl restart nginx
Now, visit your site via http://mysite.com in a browser.
Note: This setup is currently insecure since HTTPS hasn’t been configured yet.
We’ll use Certbot to enable HTTPS. Keep in mind that certificates expire every 90 days, so setting up automatic renewal is recommended.
snap install certbot --classic
sudo apt-get install -y python3-certbot-nginx
sudo certbot --nginx -d mysite.com
sudo certbot renew --dry-run
We hope this guide makes setting up your VPS easier.
For added security, consider configuring fail2ban to protect your server from brute-force attacks.
Comments