# Reverse Proxy Apache2

**URL:** <https://forum.duplicati.com/t/reverse-proxy-apache2/20009>\
**Category:** Support\
**Created:** [January 24, 2025, 2:19pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009 "2025-01-24T14:19:31Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [January 24, 2025, 2:19pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/1 "2025-01-24T14:19:31Z")

</div>

Hey,

So I have enabled --webservice-enable-forever-token=true and generate the issue-forever-token and I have added it to the header:

```plaintext

SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes On

# Add Authorization header
<IfModule mod_headers.c>
    RequestHeader set Authorization "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXAiOiJBY2Nlc3NUb2tlbiIsInNpZCI6ImZvcmV2ZXItdG9rZW4iLCJmYW0iOiJ0ZW1wb3JhcnkiLCJJhdWQiOiJodHRwczovL2R1cGxpY2F0aSJ9.m_5g4z-odWqozmndCwK-teGMx5V0nzC_n-GuevNm6X0"
</IfModule>

ProxyPass "/api" "http://localhost:8200/api"
ProxyPass "/customized" "http://localhost:8200/customized"
ProxyPass "/img" "http://localhost:8200/img"
ProxyPass "/ngax" "http://localhost:8200/ngax"
ProxyPass "/oem" "http://localhost:8200/oem"
ProxyPass "/package" "http://localhost:8200/package"
ProxyPassReverse "/api" "http://localhost:8200/api"
ProxyPassReverse "/ngax" "http://localhost:8200/ngax"
ProxyPass "/notifications" "ws://localhost:8200/notifications"

```

Until here everything is fine… I did removed then --webservice-enable-forever-token=true and started the server manually. So on the IP which is not proxied I can login normally but on the domain which is behind the proxy it gives me this error:

```plaintext
{Error: "Authorization failed due to missing cookie.", Code: 401}
Code
: 
401
Error
: 
"Authorization failed due to missing cookie."

```

What to do and what do you suggest? it is the latest canary version of Duplicati: [duplicati-2.1.0.107\_canary\_2025-01-17-linux-x64-gui.deb](https://updates.duplicati.com/canary/duplicati-2.1.0.107_canary_2025-01-17-linux-x64-gui.deb)

Debian 12 bookworm.

Thanks.

---

<div class="post-metadata">

**Author:** ![marceloduplicati](https://forum.duplicati.com/user_avatar/forum.duplicati.com/marceloduplicati/32/11557_2.png) [@marceloduplicati](https://forum.duplicati.com/u/marceloduplicati)\
**Post date:** [January 24, 2025, 2:46pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/2 "2025-01-24T14:46:08Z")

</div>

Not an expert in apache, but can you try this?

```plaintext
ProxyPassReverseCookieDomain localhost:8200 externaldomain.com
ProxyPassReverseCookiePath / /

```

[https://httpd.apache.org/docs/2.4/mod/mod\_proxy.html](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html)

---

<div class="post-metadata">

**Author:** ![kenkendk](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kenkendk/32/5305_2.png) [@kenkendk](https://forum.duplicati.com/u/kenkendk)\
**Post date:** [January 24, 2025, 3:02pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/3 "2025-01-24T15:02:57Z")

</div>

> [@BryarGh](#):
>
> ```plaintext
> {Error: "Authorization failed due to missing cookie.", Code: 401}
> Code
> : 
> 401
> Error
> : 
> "Authorization failed due to missing cookie."
> 
> ```

That is a problem with the UI then. Since it assumes it needs to authenticate, it will do so, even if it is not required. There is no good way to work around this, but I will [add it to the list of issues for the new UI](https://github.com/duplicati/ngclient/issues/104).

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [January 24, 2025, 6:14pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/4 "2025-01-24T18:14:34Z")

</div>

Thanks for you reply, no luck with this actually.

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [January 24, 2025, 6:15pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/5 "2025-01-24T18:15:53Z")

</div>

Thanks, how long do you think this will take to find a solution to this?

---

<div class="post-metadata">

**Author:** ![kenkendk](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kenkendk/32/5305_2.png) [@kenkendk](https://forum.duplicati.com/u/kenkendk)\
**Post date:** [January 28, 2025, 2:58pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/6 "2025-01-28T14:58:09Z")

</div>

> [@BryarGh](#):
>
> Thanks, how long do you think this will take to find a solution to this?

I would think we can get login sequence sorted this week, and then hopefully also get a new canary build out this week as well.

> [@BryarGh](#):
>
> `{Error: "Authorization failed due to missing cookie.", Code: 401}`

Actually… I was thinking that it is possible to hack this if you want.

The problem is that the client wants to send:

```plaintext
POST /api/v1/auth/refresh

```

So if you proxy that call to a file so it returns 200 and this content:

```plaintext
{
    "AccessToken": "bogus-token"
}

```

This should make it work. A bit of a duct-tape solution 😨

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [January 28, 2025, 8:26pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/7 "2025-01-28T20:26:01Z")

</div>

> [@kenkendk](#):
>
> ```plaintext
> {
> "AccessToken": "bogus-token"
> }
> 
> ```

I tried this as well and it failed. it does return the

```plaintext
{
    "AccessToken": "bogus-token"
}

```

But, it fails to create cookies and that way am still getting the login dialog:

```plaintext
Connection to server was rejected due to invalid authentication.

Log in again, or re-open the page from the TrayIcon (if applicable)

```

---

<div class="post-metadata">

**Author:** ![kenkendk](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kenkendk/32/5305_2.png) [@kenkendk](https://forum.duplicati.com/u/kenkendk)\
**Post date:** [January 28, 2025, 8:39pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/8 "2025-01-28T20:39:08Z")

</div>

> [@BryarGh](#):
>
> But, it fails to create cookies and that way am still getting the login dialog:

The cookies are not readable by the script. The cookie is **only** sent/set via the `/api/v1/auth/refresh` endpoint. No other endpoint relies on cookies.

You should see in the browser, that after the call to `/api/v1/auth/refresh` it will call `/api/v1/systeminfo` with the header `Authorization: Bearer bogus-token`.

The proxy should then replace the header with the forever token header, and this will cause the call to be authorized by the server.

Can you trace it further with Developer Tools in the browser?

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [January 28, 2025, 11:12pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/9 "2025-01-28T23:12:01Z")

</div>

I’m sorry for the late reply tho.

I can share with you the server link, Do you want to see? In DM.

Just tho, the /api/vi/systeminfo return data fine and everything seems fine with that part but still getting that login dialog.

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [January 28, 2025, 11:30pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/10 "2025-01-28T23:30:25Z")

</div>

Actually it worked but I needed to give it a fake token instead of writing down bogus-token lol, I missed that.

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [January 28, 2025, 11:39pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/11 "2025-01-28T23:39:46Z")

</div>

Okay final update is we have to return the actual Token or the forever-token instead of a bogus-token in /api/v1/auth/refresh. Returning the forever token worked fine but using a fake generated one didn’t work.

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [January 29, 2025, 12:10pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/12 "2025-01-29T12:10:04Z")

</div>

Another update on this:

```plaintext
SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes On

# Add Authorization header
<IfModule mod_headers.c>
    RequestHeader set Authorization "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXV"
</IfModule>
ProxyPass "/api" "http://localhost:8200/api"
ProxyPass "/customized" "http://localhost:8200/customized"
ProxyPass "/img" "http://localhost:8200/img"
ProxyPass "/ngax" "http://localhost:8200/ngax"
ProxyPass "/oem" "http://localhost:8200/oem"
ProxyPass "/package" "http://localhost:8200/package"
ProxyPassReverse "/api" "http://localhost:8200/api"
ProxyPassReverse "/ngax" "http://localhost:8200/ngax"
ProxyPass "/notifications" "ws://localhost:8200/notifications"
ProxyPassReverseCookieDomain localhost:8200 example.domain.com
ProxyPassReverseCookiePath / /

# Enable mod_rewrite
RewriteEngine On

# Match POST requests to /api/v1/auth/refresh and intercept
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^/api/v1/auth/refresh$
RewriteRule ^ - [L,R=200]

# Serve static JSON response only for /api/v1/auth/refresh
<Location "/api/v1/auth/refresh">
    Header always set Content-Type "application/json"
    SetEnvIf Request_URI "^/api/v1/auth/refresh$" STATIC_RESPONSE
    ErrorDocument 200 "{\"AccessToken\":\"eyJhbGciOiJIUzI1\"}"

</Location>

```

This works perfectly but the only issue am currently facing is the authentication not from Duplicati as we already bypassed that one but the Password Protected folders from Apache2.

If I password protect the root folder, then I can access ngax folder without any issue and the password dialog doesn’t show for me.

Manually setting a password-protected dir:

```plaintext
<Location "/">
    AuthType Basic
    AuthName "Restricted Area"
    AuthUserFile /var/.htpasswd
    Require valid-user
</Location>

```

That will also fail into a loop of requesting me to sign in , I do sign in using the admin/password but still keep requesting more and more so end up in a loop of passwording-protection.

Maybe am wrong?

---

<div class="post-metadata">

**Author:** ![kenkendk](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kenkendk/32/5305_2.png) [@kenkendk](https://forum.duplicati.com/u/kenkendk)\
**Post date:** [February 3, 2025, 8:16am UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/13 "2025-02-03T08:16:46Z")

</div>

> [@BryarGh](#):
>
> Okay final update is we have to return the actual Token or the forever-token instead of a bogus-token in /api/v1/auth/refresh. Returning the forever token worked fine but using a fake generated one didn’t work.

I think there is perhaps some configuration issue then. The downside of sending the token to the client is that it can be intercepted. Since the forever-token has a long lifetime, that would essentially break security.

It sounds like either the attachment of the token in the proxy config is not working, or the proxy avoids overwriting the bogus token, such that the Duplicati server gets the bogus token and rejects it.

> [@BryarGh](#):
>
> That will also fail into a loop of requesting me to sign in , I do sign in using the admin/password but still keep requesting more and more so end up in a loop of passwording-protection.
> 
> Maybe am wrong?

That sounds like a general Apache/Browser issue. Could it be caused by the API being called by XHR requests and this does not use the Basic Auth headers?  
In other words, the first page (most likely `index.html`) asks for credentials, you enter them, and this allows the static pages to load. Then the javascript will call the API, but this does not carry the authentication and fails, asking you for the password again?

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [February 3, 2025, 11:37am UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/14 "2025-02-03T11:37:23Z")

</div>

> [@kenkendk](#):
>
> It sounds like either the attachment of the token in the proxy config is not working, or the proxy avoids overwriting the bogus token, such that the Duplicati server gets the bogus token and rejects it.

To test your scenario, I replaced the forever-token with a fake one and all API Calls failed, But using the forever-token in the header, made the API Calls work again. The only issue is that I did generate a fake token similar to the forever-token through ChatGPT so they have minimal difference, returned it in the Refresh file and tested it to find out the Refresh keeps failing. I’m not sure why is this happening but most likely it is being overridden and rejected by the Duplicati server.

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [February 3, 2025, 8:09pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/15 "2025-02-03T20:09:16Z")

</div>

> [@kenkendk](#):
>
> That sounds like a general Apache/Browser issue. Could it be caused by the API being called by XHR requests and this does not use the Basic Auth headers?  
> In other words, the first page (most likely `index.html`) asks for credentials, you enter them, and this allows the static pages to load. Then the javascript will call the API, but this does not carry the authentication and fails, asking you for the password again?

As for this I couldn’t find an explanation could be the one you mentioned… As for anyone else who want to have the same setup, Using **SSO (Single Sign-On)** with Google bypassed that issue for me 🙂

Only, the refresh without returning the forever-token it doesn’t work. The token seems to expire in a short time and the refresh function just refreshes and renew it, but the forever-token is created to not expire after login. So basically you have to always return that token no matter what.

---

<div class="post-metadata">

**Author:** ![kenkendk](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kenkendk/32/5305_2.png) [@kenkendk](https://forum.duplicati.com/u/kenkendk)\
**Post date:** [February 5, 2025, 4:02pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/16 "2025-02-05T16:02:55Z")

</div>

> [@BryarGh](#):
>
> Only, the refresh without returning the forever-token it doesn’t work. The token seems to expire in a short time and the refresh function just refreshes and renew it, but the forever-token is created to not expire after login. So basically you have to always return that token no matter what.

We are [building the logic for handling the proxy situation into the new UI](https://github.com/duplicati/ngclient/issues/107).

---

<div class="post-metadata">

**Author:** ![BryarGh](https://forum.duplicati.com/user_avatar/forum.duplicati.com/bryargh/32/10536_2.png) [@BryarGh](https://forum.duplicati.com/u/BryarGh)\
**Post date:** [February 5, 2025, 10:26pm UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/17 "2025-02-05T22:26:54Z")

</div>

Yup, I was following that issue on Github, thanks for your effort. May I know when it will be released?

---

<div class="post-metadata">

**Author:** ![kenkendk](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kenkendk/32/5305_2.png) [@kenkendk](https://forum.duplicati.com/u/kenkendk)\
**Post date:** [February 6, 2025, 10:29am UTC](https://forum.duplicati.com/t/reverse-proxy-apache2/20009/18 "2025-02-06T10:29:51Z")

</div>

It will be part of the next canary build. Release for that is planned for end of this week, or start of next week depending on the time taken to resolve some minor issues.
