N8n with Docker Compose and Apache as a reverse proxy

Hello everyone! I’m fairly new to n8n and I’m currently attempting to deploy it to my server using Docker Compose, along with an Apache server as a reverse proxy that runs outside of Docker and Cloudflare. I’ve been searching for a similar installation guide on this forum, but haven’t found one yet. So, I’ve made some modifications to the docker-compose.yml file, but I’m not entirely sure if it will work correctly in this configuration. If anyone can tell me if this works or offer any advice I would be very grateful!

docker-compose.yml

version: "3"

services:
  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=n8n.domain.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - NODE_ENV=production
      - WEBHOOK_URL=https://n8n.domain.com/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - .n8n:/home/node/.n8n

n8n.domain.com.conf (apache config)

<VirtualHost *:443>
    ServerName n8n.domain.com
    RemoteIPHeader CF-Connecting-IP

    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/n8n.domain.com/n8n.domain.com.pem
    SSLCertificateKeyFile /etc/apache2/ssl/n8n.domain.com/n8n.domain.com.key

    ProxyPass / http://127.0.0.1:5678/
    ProxyPassReverse / http://127.0.0.1:5678/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Is there anyone who could take a short look?

Hey @3rKaN_BRATTE,

It looks like it could possibly work but we have not tested every reverse proxy configuration so this is one of those cases where it would come down to your knowledge of it. Looking at the n8n configuration part it looks like it will work, I would probably remove the basic auth sections as that will be removed in v1.0 anyway so might as well start right.

In your cloudflare configuration make sure it isn’t caching anything as that is known to cause issues, I would give it a run and see if you run into any issues and we can work it out from there.

1 Like

Hey @Jon, thank you for your reply and for evaluating my configs. Regarding disabling basic authentication, what is the alternative solution, as the built-in user management feature appears to be a paid feature according to the website. User management | n8n Docs

@Jon am I being misled by the term ‘Basic Auth’? Could it simply be another layer of security before the regular login, or is it actually the standard login method?

Exactly. User management is free. The thing that is paid is the collaboration part. So if you want to share workflows or credentials.

@jan So just to clarify, the ‘Built-in self-hosted user management’ feature is free? I apologize for asking again, but I’m still a bit confused and wanted to double-check.

Never mind, I managed to figure it out. Thanks for your help anyway! By the way, kudos to this amazing tool! :slight_smile:

2 Likes

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