Skip to main content
Skip table of contents

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

CODE
sudo apt update
sudo apt install nginx -y

Start and enable Nginx:

CODE
sudo systemctl start nginx
sudo systemctl enable nginx


Step 2: Configure Nginx Server Block for yourwebsite.com

Create a new config file:

CODE
sudo nano /etc/nginx/sites-available/yourwebsite.com

Paste the following content:

CODE
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:

CODE
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

CODE
sudo apt install certbot python3-certbot-nginx -y

Step 4: (Optional) Obtain SSL Certificate with Certbot

Replace yourwebsite.com with your actual domain:

CODE
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:

CODE
https://yourwebsite.com/hash

It should forward the request to:

CODE
http://hash.yourwebsite.com/


Step 6: (Optional) Test Auto-Renewal

Verify Certbot renewal service:

CODE
sudo systemctl list-timers | grep certbot

Simulate a dry run renewal:

CODE
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.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.