# NGINX Configuration Guide

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 href="#nginxconfigurationguide-prerequisites" id="nginxconfigurationguide-prerequisites"></a>

* 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** <a href="#nginxconfigurationguide-step1-installnginx" id="nginxconfigurationguide-step1-installnginx"></a>

```
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 <a href="#nginxconfigurationguide-step2-configurenginxserverblockforyourwebsite.com" id="nginxconfigurationguide-step2-configurenginxserverblockforyourwebsite.com"></a>

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** <a href="#nginxconfigurationguide-step3-optional-installcertbotandnginxplugin" id="nginxconfigurationguide-step3-optional-installcertbotandnginxplugin"></a>

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

***

### **Step 4: (Optional) Obtain SSL Certificate with Certbot** <a href="#nginxconfigurationguide-step4-optional-obtainsslcertificatewithcertbot" id="nginxconfigurationguide-step4-optional-obtainsslcertificatewithcertbot"></a>

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** <a href="#nginxconfigurationguide-step5-verifysetup" id="nginxconfigurationguide-step5-verifysetup"></a>

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** <a href="#nginxconfigurationguide-step6-optional-testauto-renewal" id="nginxconfigurationguide-step6-optional-testauto-renewal"></a>

Verify Certbot renewal service:

```
sudo systemctl list-timers | grep certbot
```

Simulate a dry run renewal:

```
sudo certbot renew --dry-run
```

***

### **Conclusion** <a href="#nginxconfigurationguide-conclusion" id="nginxconfigurationguide-conclusion"></a>

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

{% hint style="danger" %}
After enabling Cookie lifetime extender, the DCP will give a proxy code that is expected to be setup on `https://domain.*/hash` however, if it is set up on `https://www.domain.*/hash` it will cause a CORS Error on the Cookie Lifetime Extender Requests.

For more details on WWW configuration follow this [guide](https://docs.jentis.com/key-features/cookie-lifetime-extender/configure-your-tracking#www-configuration-guide-optional).
{% endhint %}

***

If you have any questions or feedback, please open a request on our [Helpdesk](https://jentis.atlassian.net/servicedesk/customer/portal/1/group/1/create/220).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jentis.com/key-features/cookie-lifetime-extender/cookie-lifetime-extender-webserver-cdn-configurations/nginx-configuration-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
