Deploying a Web Application with Nginx and SSL
Install Nginx on your Ubuntu server, configure server blocks for your domain, and set up free SSL certificates with Let's Encrypt and Certbot.
Need a server? Get $200 free credits on DigitalOcean- A secured Ubuntu 24.04 server (see exercise 2: Securing Your Linux Server)
- A domain name pointed to your server's IP address
- SSH access as a sudo user
- UFW firewall configured with ports 80 and 443 open
You need a running Linux server for this exercise. Any Ubuntu server works, but we recommend DigitalOcean for quick setup.
Get $200 in free credits to get started.
Disclosure: This is an affiliate link. We may earn a commission at no extra cost to you.
- Install and configure Nginx as a web server
- Set up server blocks (virtual hosts) for a domain
- Deploy a static website to the server
- Install Certbot and obtain a free SSL certificate from Let's Encrypt
- Configure automatic HTTP to HTTPS redirection
- Set up automatic certificate renewal
Install Nginx
Install Nginx from the Ubuntu package repository and verify it is running.
Create the Website Directory and a Sample Page
Set up the directory structure for your website and create a simple HTML page to test the configuration.
Create an Nginx Server Block
Nginx uses server blocks (similar to Apache virtual hosts) to serve different sites. Create one for your domain.
Enable the Server Block and Test
Create a symlink to enable the site, test the Nginx configuration, and reload.
Verify Your Domain Points to the Server
Before requesting an SSL certificate, your domain must resolve to your server's IP address. Verify this with dig or nslookup.
Install Certbot and Obtain an SSL Certificate
Certbot is the official Let's Encrypt client. It handles obtaining and installing SSL certificates automatically.
Verify HTTPS and HTTP Redirect
Certbot should have configured Nginx to redirect HTTP traffic to HTTPS automatically. Verify both the redirect and the SSL certificate.
Set Up Automatic Certificate Renewal
Let's Encrypt certificates expire after 90 days. Certbot installs a systemd timer to renew them automatically. Verify it is set up and test a dry run.
Found an issue?