Nginx Configuration Guide
Nginx Reverse Proxy Setup with HTTPS on Ubuntu 22.04
This guide walks you through setting up an Nginx web server on Ubuntu 22.04 with:
A reverse proxy configuration where yourwebsite.com/hash points to hash.yourwebsite.com
HTTPS support using Let’s Encrypt via Certbot
Prerequisites
A server running Ubuntu 22.04
A registered domain name (e.g., yourwebsite.com )
DNS A record pointing yourwebsite.com to your server’s IP
Step 1: Install Nginx
sudo apt update
sudo apt install nginx -y
Start and enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
Step 2: Configure Nginx Server Block for yourwebsite.com
Create a new config file:
sudo nano /etc/nginx/sites-available/yourwebsite.com
Paste the following content:
server {
listen 80;
server_name yourwebsite.com;
location /hash {
proxy_pass https://hash.yourwebsite.com/;
proxy_set_header Host hash.yourwebsite.com;
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;
client_max_body_size 50M;
}
access_log /var/log/nginx/yourwebsite.com_access.log;
error_log /var/log/nginx/yourwebsite.com_error.log;
}
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/yourwebsite.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 3: (Optional) Install Certbot and Nginx Plugin
sudo apt install certbot python3-certbot-nginx -y
Step 4: (Optional) Obtain SSL Certificate with Certbot
Replace yourwebsite.com with your actual domain:
sudo certbot --nginx -d yourwebsite.com
Certbot will:
Automatically configure HTTPS in your Nginx config
Enable HTTP to HTTPS redirection
Reload Nginx automatically
Step 5: Verify Setup
Test the proxy by visiting:
https://yourwebsite.com/hash
It should forward the request to:
http://hash.yourwebsite.com/
Step 6: (Optional) Test Auto-Renewal
Verify Certbot renewal service:
sudo systemctl list-timers | grep certbot
Simulate a dry run renewal:
sudo certbot renew --dry-run
Conclusion
You now have:
Nginx running on Ubuntu 22.04
HTTPS enabled via Let’s Encrypt
A reverse proxy from yourwebsite.com/hash to hash.yourwebsite.com
If you have any questions or feedback, please open a request on our Helpdesk.