N8n in a sublocation using Apache as Reverse proxy

Hi, I’m trying to installing n8n in a sublocation using Apache as a reverse proxy. I would like to access n8n using https://mydomain/n8n but when I try I get 404 on all elements.
These are my apache configuration and docker-compose.yml

<VirtualHost *:443>
    SSLProxyEngine Off
        SSLProxyCheckPeerCN Off
        ProxyPreserveHost On
        ProxyRequests Off

        LoadModule proxy_html_module modules/mod_proxy_html.so
        LoadModule substitute_module modules/mod_substitute.so
        LoadModule filter_module modules/mod_filter.so

        LogLevel filter:debug substitute:debug

        <Location /n8n>
        ProxyPass http://127.0.0.1:5678/n8n/
        ProxyPassReverse http://127.0.0.1:5678/n8n/
        SetOutputFilter INFLATE;proxy-html;DEFLATE
        ProxyHTMLURLMap / /n8n/
        ProxyHTMLFixups On
        </Location>

</VirtualHost>
  n8n:
     image: crazymax/n8n:latest
     platform: linux/arm/v7
     restart: unless-stopped
     ports:
       - 5678:5678
     environment:
       - N8N_HOST=https://andrewthefx-everest.nord
       - N8N_PORT=5678
       - N8N_PROTOCOL_https
       - NODE_ENV=production
       - WEBHOOK_URL=https://andrewthefx-everest.nord/n8n
       - GENERIC_TIMEZONE=Europe/Berlin
       - N8N_TUNNEL_SUBDOMAIN=/n8n
       - N8N_PROXY_HOPS=1
       - N8N_PATH=/n8n
       - VUE_APP_PATH=/n8n
     volumes:
       - n8n_data:/home/node/.n8n
       - ./local-files:/files

I managed to get it working. Those are the configurations:
Apache

    RewriteEngine On
    RewriteRule ^/n8n/(.*)$ http://127.0.0.1:5678/$1 [P,L]

    ProxyPreserveHost On

    ProxyPass /n8n/ http://127.0.0.1:5678/n8n/
    ProxyPassReverse /n8n/ http://127.0.0.1:5678/n8n/
    ProxyPassReverseCookiePath / /n8n/
    ProxyPassReverseCookieDomain 127.0.0.1 yourdomain

    <Location /n8n/>
        RequestHeader set X-Forwarded-Proto "https"
        RequestHeader set X-Forwarded-Host "yourdomain"
        RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s
    </Location>

docker

  n8n:
     image: crazymax/n8n:latest
     platform: linux/arm/v7
     restart: unless-stopped
     ports:
       - 5678:5678
     environment:
       - N8N_HOST=yourdomain
       #- N8N_HOST=localhost
       - N8N_PORT=5678
       - N8N_PROTOCOL=http
       - NODE_ENV=production
       - WEBHOOK_URL=https://yourdomain/n8n
       - GENERIC_TIMEZONE=Europe/Berlin
       - N8N_PROXY_HOPS=1
       - N8N_PATH=/n8n/
       - VUE_APP_PATH=/n8n/
       - N8N_BASIC_AUTH_ACTIVE=false
       - N8N_USER_MANAGEMENT_DISABLED=true
     volumes:
       - n8n_data:/home/node/.n8n
       - ./local-files:/files
1 Like

Thank you so much! It worked like a charm.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.