Deploy your website to a Virtual Private Server - server setup, SSH, nginx configuration, HTTPS with Let's Encrypt, and basic security hardening.
Deploying to a VPS with Nginx
You have a working website. Now let us put it on the internet. This chapter walks through the entire process: getting a server, setting it up, configuring nginx to serve your files, and securing the site with HTTPS.
What is a VPS?
A Virtual Private Server (VPS) is a virtual machine running in a data center. You get root access to a full Linux server that runs 24/7. Unlike shared hosting, you control everything - the operating system, the software, the firewall.
Choosing a provider
Popular VPS providers:
For a simple static website, the cheapest plan from any provider is more than enough. This guide uses **Ubuntu 22.04 LTS ** as the operating system - choose it when creating your server.
What you need before starting
- A VPS running Ubuntu 22.04 LTS (or newer)
- A domain name (optional but recommended - e.g.,
yoursite.com) - The website files from the previous chapter
- A terminal on your local machine
Step 1: initial server setup
When you create a VPS, the provider gives you the server's IP address and a root password (or lets you add an SSH key).
Connect to your server
Replace YOUR_SERVER_IP with the actual IP (e.g., 203.0.113.42). On the first connection, you will be asked to
confirm the server's fingerprint - type yes.
Update the system
Create a non-root user
Running as root is dangerous - a mistake can destroy the entire system. Create a regular user:
You will be prompted to set a password and fill in optional details (you can skip the details by pressing Enter).
Grant the user sudo privileges:
Set up SSH key authentication
SSH keys are more secure than passwords. On your local machine (not the server), generate a key pair if you do not already have one:
Press Enter to accept the default file location. Set a passphrase for extra security.
Copy the public key to the server:
Test the connection:
You should log in without being asked for a password.
Disable password authentication
Once SSH keys work, disable password login for security. On the server, edit the SSH configuration:
Find and change these lines:
Restart the SSH service:
Warning: Make sure your SSH key login works before doing this. If you lock yourself out, you will need to use the provider's console access.
Step 2: set up the firewall
Ubuntu comes with ufw (Uncomplicated Firewall):
Result:
Step 3: install nginx
Verify it is running:
Open your browser and navigate to http://YOUR_SERVER_IP. You should see the default nginx welcome page.
How nginx works
Nginx is a web server - it listens for HTTP requests and serves files in response. For a static website, nginx simply serves your HTML, CSS, and JavaScript files directly to the browser.
The configuration lives in /etc/nginx/. Key paths:
Step 4: upload your website files
Create a directory for your site on the server:
From your local machine, upload the files using rsync:
Breakdown:
-a- archive mode (preserves permissions, timestamps)-v- verbose output-z- compress during transfer--delete- remove files on the server that no longer exist locally
Alternative using scp:
Verify the files are there:
Result:
Step 5: configure nginx
Create a new site configuration:
Paste this configuration:
Replace YOUR_DOMAIN_OR_IP with your domain (e.g., yoursite.com) or your server's IP address.
Enable the site
Result:
Reload nginx:
Open http://YOUR_DOMAIN_OR_IP in your browser. Your website is live.
Step 6: set up a domain (optional)
If you have a domain name, point it to your server:
- Go to your domain registrar's DNS settings
- Add an A record pointing to your server's IP:
DNS changes can take a few minutes to a few hours to propagate. You can check with:
Once the domain resolves to your server IP, update the nginx config:
Reload nginx:
Step 7: HTTPS with Let's Encrypt
HTTPS is mandatory for any website in production. Let's Encrypt provides free SSL certificates.
Install Certbot
Obtain and install a certificate
Certbot will:
- Verify you own the domain
- Obtain a certificate
- Automatically update your nginx config to use HTTPS
- Set up HTTP-to-HTTPS redirect
Follow the prompts - enter your email and agree to the terms.
Verify HTTPS
Open https://yoursite.com in your browser. You should see the lock icon.
Automatic renewal
Let's Encrypt certificates expire every 90 days. Certbot sets up automatic renewal:
If the dry run succeeds, renewals will happen automatically via a systemd timer.
Verify the timer is active:
Step 8: basic security hardening
Automatic security updates
Select "Yes" when asked to enable automatic updates.
Fail2Ban - block brute-force attacks
Create a local configuration:
Start and enable:
Change the SSH port (optional)
Changing the default SSH port (22) reduces automated login attempts:
Change Port 22 to another port (e.g., Port 2222):
Update the firewall:
Now connect with:
Deploying updates
Whenever you update your website locally, deploy the changes with a single command:
No server restart needed - nginx serves files directly from disk.
A simple deploy script
Create deploy.sh in your project root:
Make it executable and run it:
Verifying the deployment
After deploying, check these things:
- Site loads: Open your domain in a browser - all pages should work.
- HTTPS works: The lock icon should appear in the address bar.
- No mixed content: Open the browser console and check for warnings about HTTP resources on an HTTPS page.
- Performance: Open Chrome DevTools → Network tab, reload the page, and verify static assets have cache headers.
- Mobile: Test on a phone or use the responsive mode in dev tools.
Quick checks from the command line
Complete server setup checklist
Here is everything we did, in order:
- Created a VPS with Ubuntu 22.04 LTS
- Updated the system (
apt update && apt upgrade) - Created a non-root user with sudo
- Set up SSH key authentication
- Disabled password authentication
- Configured the firewall with
ufw - Installed nginx
- Uploaded website files
- Created nginx site configuration
- Pointed the domain to the server (DNS)
- Installed HTTPS with Let's Encrypt
- Set up automatic security updates
- Installed Fail2Ban
- Created a deploy script
What comes next
You now have a website live on the internet, served by nginx over HTTPS. The next chapter introduces TypeScript - static types for JavaScript that catch bugs before they reach production.
Continue with: TypeScript
After that, you could:
- Add a CI/CD pipeline - automatically deploy when you push to Git
- Add a backend - use Node.js with Express behind nginx as a reverse proxy
- Add monitoring - use tools like
htop,nginxaccess logs, or services like UptimeRobot - Add a database - SQLite for small projects, PostgreSQL for larger ones
- Learn Docker - containerize your application for easier deployment
- Explore frameworks - React, Vue, Svelte, or Next.js for more complex applications
Summary
- A VPS gives you a full Linux server in the cloud.
- SSH keys are more secure than passwords - disable password authentication.
- nginx serves static files efficiently with caching and security headers.
- Let's Encrypt provides free HTTPS certificates with automatic renewal.
- Fail2Ban and unattended-upgrades protect against common threats.
- Deploy updates with a single
rsynccommand.
Congratulations - you have gone from writing your first console.log("Hello, world!") to deploying a live website. The
fundamentals you have learned (variables, functions, arrays, objects, DOM, events, fetch, deployment) are the foundation
for everything else in web development. Keep building.