# Apache Configuration Guide

This guide walks you through setting up an Apache web server on Ubuntu 22.04 with:

* A reverse proxy configuration where your `website.com/hash` points to `hash.yourwebsite.com`
* HTTPS support using Let’s Encrypt via Certbot

***

### **Prerequisites** <a href="#apacheconfigurationguide-prerequisites" id="apacheconfigurationguide-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 Apache Web Server** <a href="#apacheconfigurationguide-step1-installapachewebserver" id="apacheconfigurationguide-step1-installapachewebserver"></a>

```
sudo apt update
sudo apt install apache2 -y
```

***

### **Step 2: Enable Required Apache Modules** <a href="#apacheconfigurationguide-step2-enablerequiredapachemodules" id="apacheconfigurationguide-step2-enablerequiredapachemodules"></a>

```
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod rewrite
```

Restart Apache to apply changes:

```
sudo systemctl restart apache2
```

***

### **Step 3: Configure Apache Virtual Host for site.com** <a href="#apacheconfigurationguide-step3-configureapachevirtualhostforsite.com" id="apacheconfigurationguide-step3-configureapachevirtualhostforsite.com"></a>

{% hint style="info" %}
Replace `yourwebsite.com` below with your actual domain
{% endhint %}

Create a new site configuration file:

```
sudo nano /etc/apache2/sites-available/yourwebsite.com.conf
```

Paste the following content:

```
<VirtualHost *:80>
    ServerName yourwebsite.com

    DocumentRoot /var/www/html
    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    ProxyPreserveHost Off
        <Proxy *>
           Require all granted
        </Proxy>
    ProxyPass /hash http://hash.yoursite.com
    ProxyPassReverse /hash http://hash.yoursite.com/

    ErrorLog ${APACHE_LOG_DIR}/yoursite.com_error.log
    CustomLog ${APACHE_LOG_DIR}/yoursite.com_access.log combined
</VirtualHost>
```

Enable the new site and disable the default:

```
sudo a2ensite site.com.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2
```

***

{% hint style="info" %}
Steps 4, 5, and 6 are only necessary if you do not have a signed certificate for your web server already
{% endhint %}

### **Step 4: Install Certbot and Apache Plugin** <a href="#apacheconfigurationguide-step4-installcertbotandapacheplugin" id="apacheconfigurationguide-step4-installcertbotandapacheplugin"></a>

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

***

### **Step 5: Obtain SSL Certificate with Certbot** <a href="#apacheconfigurationguide-step5-obtainsslcertificatewithcertbot" id="apacheconfigurationguide-step5-obtainsslcertificatewithcertbot"></a>

{% hint style="info" %}
Replace `yourwebsite.com` below with your actual domain
{% endhint %}

```
sudo certbot --apache -d yourwebsite.com
```

Certbot will:

* Automatically configure HTTPS in Apache
* Enable HTTP to HTTPS redirection
* Reload Apache automatically

***

### **Step 6: (Optional) Test Auto-Renewal** <a href="#apacheconfigurationguide-step6-optional-testauto-renewal" id="apacheconfigurationguide-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
```

***

### **Step 7: Verify Setup** <a href="#apacheconfigurationguide-step7-verifysetup" id="apacheconfigurationguide-step7-verifysetup"></a>

Test the proxy by visiting:

```
https://yourwebsite.com/hash
```

It should forward the request to:

```
http://hash.yourwebsite.com/
```

***

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

You now have:

* Apache 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).
