Heimdall icon indicating copy to clipboard operation
Heimdall copied to clipboard

Reverse Proxy with Apache2 several wrong Endpoints

Open GAS85 opened this issue 3 years ago • 2 comments

Hello dear community,

I would like to use Heimdall with Apache2 Reverse Proxy as sub path and do create following configuration in it:

#Heimdall
Redirect 301 "/heimdallExternal" "/heimdallExternal/"
	<Location /heimdallExternal/>
		ProxyPreserveHost On
		ProxyPass http://localhost:9012/ retry=0 timeout=5
		ProxyPassReverse http://localhost:9012/
		RequestHeader set Connection ""
		RequestHeader set x-forwarded-proto "https"
	</Location>

My docker compose file:

version: "3.6"

services:
  heimdallExternal:
    image: lscr.io/linuxserver/heimdall
    container_name: heimdallExternal
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    volumes:
      - ${WORKINGDIR}/docker/heimdallExternal/:/config
    ports:
      - 9012:80
    restart: unless-stopped

I did update ..www/.env so that my hostname with sub path are configured:

APP_NAME=Heimdall
APP_ENV=local
APP_KEY=base64:xxxx
APP_DEBUG=false
APP_URL=https://DOMAIN/heimdallExternal

...

After that I'm able to use Heimdall under https://DOMAIN/heimdallExternal/. Unfortunately it has few issues:

1. Wrong Redirect after login

  1. Crete user and protect it with password
  2. Visit https://DOMAIN/heimdallExternal/ and see Login page grafik
  3. Enter password and Hit enter --> See an error page or wrong Page not Heimdall any more.
    • Open Network inspector and see correct POST request.
    • After it comes GET with wrong answer in header location: https://DOMAIN instead of location: https://DOMAIN/heimdallExternal/
  4. Workaround - visit again https://DOMAIN/heimdallExternal/.

2. SOLVED - Wrong Link by editing Order

  1. Visit https://DOMAIN/heimdallExternal/ and change order of TABs
  2. Save and see that after page reloading nothing saved and defaults (initial) state been shown
  3. Root Cause:
    • Order Endpoint ignores Settings, instead doing POST on https://DOMAIN/heimdallExternal/order it does on endpoint without / between sub path and order endpoint: https://DOMAIN/heimdallExternalorder.
    • Even more it ignores APP_URL configuration from .env and expect POST on http://localhost:9012/order instead of http://localhost:9012/heimdallExternal/order
  4. Workaround - add rewrite rule to the Apache2 Server:
# You have to merge "order" and your sub path to "subPathorder"
	<Location /heimdallExternalorder>
		ProxyPreserveHost On
		ProxyPass http://localhost:9012/order retry=0 timeout=5
		ProxyPassReverse http://localhost:9012/order
		RequestHeader set Connection ""
		RequestHeader set x-forwarded-proto "https"
	</Location>

3. SOLVED - Background Image wrong URL

  1. Visit https://DOMAIN/heimdallExternal/ and change your background Image
  2. Standard image will be shown
  3. Root Cause:
    • Image Endpoint ignores Settings, instead of doing GET on https://DOMAIN/heimdallExternal/storage/... it does on endpoint endpoint: https://DOMAIN/storage/....
  4. Workaround - add rewrite rule to the Apache2 Server:
	<Location /storage/>
		ProxyPreserveHost On
		ProxyPass http://localhost:9012/storage/ retry=0 timeout=5
		ProxyPassReverse http://localhost:9012/storage/
		RequestHeader set Connection ""
		RequestHeader set x-forwarded-proto "https"
	</Location>

4. SOLVED - Wrong link by editing Pins

  1. Visit https://DOMAIN/heimdallExternal/ and change your pins on the left panel
  2. Nothing will happens
  3. Root Cause:
    • Endpoint ignores Settings, instead of doing GET on https://DOMAIN/heimdallExternal/items/... it does on endpoint endpoint: https://DOMAIN/heimdallExternalitems/....
  4. Workaround - add rewrite rule to the Apache2 Server:
	<Location /heimdallExternalitems/>
		ProxyPreserveHost On
		ProxyPass http://localhost:9012/items/ retry=0 timeout=5
		ProxyPassReverse http://localhost:9012/items/
		RequestHeader set Connection ""
		RequestHeader set x-forwarded-proto "https"
	</Location>

GAS85 avatar Mar 15 '22 08:03 GAS85

I have a similar setup to you and experience some of your issues.

# Config for Heimdall in Apache2
<Location /home>
  ProxyPass http://localhost:8001
  ProxyPassReverse /home
  RequestHeader set X-Forwarded-Proto "https"
</Location>

I fixed your issues 2, 3, 4 by adding a / add the end of the APP_URL value, i.e. APP_URL=https://my.domain/home/. However, I'm still experiencing the wrong redirect after login.

In addition, the autofill features with the "Application Type" and "Website" buttons in /items/create don't work when going through the proxy.

prs513rosewood avatar Mar 31 '22 12:03 prs513rosewood

Thats cool, thanks! Than we can close 2,3,4. Only 1 is remaining 😄

I would also suggest to replace APP_URL=https://FQDN/blabla with something like APP_URL="${VARIABLE_APP_URL}" to make it configurable in .env file.

GAS85 avatar Jun 10 '22 08:06 GAS85

BUG#1 remain still. It lead me back to localhost after login, while heimdall was on a remote server.😂

1-1-2 avatar Feb 22 '23 15:02 1-1-2

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Apr 09 '23 15:04 github-actions[bot]

Nope, still valid.

GAS85 avatar Apr 10 '23 10:04 GAS85

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar May 11 '23 15:05 github-actions[bot]

There is activity, bad bot.

GAS85 avatar May 22 '23 11:05 GAS85

Have you solved it? I would like to use nginx proxy

iamckun avatar May 26 '23 08:05 iamckun

same problem with Traefik, after login app doesnt follow APP_URL and goes to root. And im also for "APP_URL" environment variable docker deployment. Everything else working

rado78945 avatar Jun 20 '23 13:06 rado78945

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jul 20 '23 15:07 github-actions[bot]

Still valid

GAS85 avatar Jul 24 '23 09:07 GAS85

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

LinuxServer-CI avatar Aug 23 '23 15:08 LinuxServer-CI

issue-activity 🧟

GAS85 avatar Aug 24 '23 13:08 GAS85

No one within our team uses Apache for reverse proxy, we focus on using nginx and our SWAG solution.

j0nnymoe avatar Aug 24 '23 17:08 j0nnymoe

It is ok, nginx and apache2 are quite similar, there is only configuration way is different. Nevertheless, problem is not in apache2, but problem is in Heimdall itself, it is not correctly supports subpath - redirect to the wrong place, resources from the root, etc. from the list above. If you can provide here nginx configuration for subpath, that will work and cover all points from above, I can simply map it to the apache2. But as I sad, it is not apache2 issue.

GAS85 avatar Aug 25 '23 07:08 GAS85

Last I checked, due to it being based on laravel, it doesn't like working in subfolders. We have a subfolder conf for SWAG but it looks like it's only designed to be used when wanting heimdall on the root of the domain. https://github.com/linuxserver/reverse-proxy-confs/blob/master/heimdall.subfolder.conf.sample

j0nnymoe avatar Aug 25 '23 07:08 j0nnymoe

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

LinuxServer-CI avatar Sep 24 '23 15:09 LinuxServer-CI

As ticket was closed, but I found solution to simply remove all staff by Apache itself.

My URL is https://<DOMAIN>/heimdallExternal/. Docker runned on the same system under 'http://localhost:9012/'.

You need 2 Apache Modules mod_substitute and mod_filter Apache config:

Redirect 301 "/heimdallExternal" "/heimdallExternal/"
	<Location /heimdallExternal/>
		ProxyPass http://localhost:9012/ retry=0 timeout=5
		ProxyPassReverse http://localhost:9012/
		RequestHeader set Connection ""

		AddOutputFilterByType SUBSTITUTE text/html text/xml text/javascript application/json
		# We will get Zipped answer, so we need unpack, substitute and pack back.
		SetOutputFilter INFLATE;SUBSTITUTE;DEFLATE
		Substitute "s|http://localhost:9012|https://<DOMAIN>/heimdallExternal|i"
	</Location>

Heimdall config ..www/.env (usually you do not need to update):

APP_NAME=Heimdall
APP_ENV=local
APP_KEY=base64:xxxx
APP_DEBUG=false
APP_URL=http://localhost:9012

GAS85 avatar Nov 28 '23 15:11 GAS85

This issue is locked due to inactivity

github-actions[bot] avatar Dec 28 '23 15:12 github-actions[bot]