N8N as a subfolder with nginx

Hi,

We are setting up N8N to run as a subfolder on http://www.example.com/automation

I’ve added the following in .env

# The subfolder to serve from
SUBFOLDER=automation
N8N_PATH=/automation/

In NGINX configuration, I’ve added a reverse proxy configuration for the n8n container

location /automation {
     proxy_pass http://n8n:5678;
     add_header X-Content-Type-Options nosniff;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Forwarded-Proto $scheme;
   }

Error we get is 404 in nginx for css and scripts to load

nginx_1 | 103.72.143.116 - - [21/Sep/2021:02:28:21 +0000] “GET /automation/css/app.1952dc89.css HTTP/1.1” 404 170 “https://www.example.com/automation/” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36” “-”
nginx_1 | 51.103.28.11 - - [21/Sep/2021:02:28:21 +0000] “GET /auth/oauth2/info?access_token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIyNDcwNDE4OTU1MzQ5NTI0NTIiLCJleHAiOjE2MzIxOTg1MDAsInJvbGVzIjoiMiIsInNjb3BlIjoicHJvZmlsZSIsInN1YiI6IjI0NzEwNDI2MTE3Nzk5OTM2NSJ9.WSJVli3iNiUDbpyaPwCcY-YLWarZttxKpEmodlT1FMJmNwrj9I3kOAitLoRPppIxoxbtmD54vQHNj1M8nHPxbg HTTP/1.1” 200 224 “-” “-” “-”
nginx_1 | 103.72.143.116 - - [21/Sep/2021:02:28:21 +0000] “GET /automation/js/app.8dbcb3d5.js HTTP/1.1” 404 168 “https://www.example.com/automation/” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36” “-”
nginx_1 | 51.103.28.11 - - [21/Sep/2021:02:28:21 +0000] “GET /auth/oauth2/info?access_token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIyNDcwNDE4OTU1MzQ5NTI0NTIiLCJleHAiOjE2MzIxOTg1MDAsInJvbGVzIjoiMiIsInNjb3BlIjoicHJvZmlsZSIsInN1YiI6IjI0NzEwNDI2MTE3Nzk5OTM2NSJ9.WSJVli3iNiUDbpyaPwCcY-YLWarZttxKpEmodlT1FMJmNwrj9I3kOAitLoRPppIxoxbtmD54vQHNj1M8nHPxbg HTTP/1.1” 200 224 “-” “-” “-”
nginx_1 | 103.72.143.116 - - [21/Sep/2021:02:28:21 +0000] “GET /automation/fonts.css HTTP/1.1” 404 159 “https://www.example.com/automation/” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36” “-”
nginx_1 | 51.103.28.11 - - [21/Sep/2021:02:28:21 +0000] “GET /auth/oauth2/info?access_token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIyNDcwNDE4OTU1MzQ5NTI0NTIiLCJleHAiOjE2MzIxOTg1MDAsInJvbGVzIjoiMiIsInNjb3BlIjoicHJvZmlsZSIsInN1YiI6IjI0NzEwNDI2MTE3Nzk5OTM2NSJ9.WSJVli3iNiUDbpyaPwCcY-YLWarZttxKpEmodlT1FMJmNwrj9I3kOAitLoRPppIxoxbtmD54vQHNj1M8nHPxbg HTTP/1.1” 200 224 “-” “-” “-”
nginx_1 | 103.72.143.116 - - [21/Sep/2021:02:28:21 +0000] “GET /automation/js/chunk-vendors.44c26054.js HTTP/1.1” 404 178 “https://www.example.com/automation/” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36” “-”
nginx_1 | 51.103.28.11 - - [21/Sep/2021:02:28:21 +0000] “GET /auth/oauth2/info?access_token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIyNDcwNDE4OTU1MzQ5NTI0NTIiLCJleHAiOjE2MzIxOTg1MDAsInJvbGVzIjoiMiIsInNjb3BlIjoicHJvZmlsZSIsInN1YiI6IjI0NzEwNDI2MTE3Nzk5OTM2NSJ9.WSJVli3iNiUDbpyaPwCcY-YLWarZttxKpEmodlT1FMJmNwrj9I3kOAitLoRPppIxoxbtmD54vQHNj1M8nHPxbg HTTP/1.1” 200 224 “-” “-” “-”
nginx_1 | 103.72.143.116 - - [21/Sep/2021:02:28:21 +0000] "GET /automation/js/app.8dbcb3d5.js

Hi @navdeep,

What config are you using to run n8n with?

Hi @jon, please find below my docker-compose config file for n8n

n8n:
    #image: n8nio/n8n
    build:
      context: ./n8n/src
      dockerfile: docker/images/n8n-custom/Dockerfile
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - GENERIC_TIMEZONE
      - N8N_OAUTH2_AUTH_ACTIVE=true
      - N8N_OAUTH2_AUTHORIZATION_URI
      - N8N_OAUTH2_ACCESS_TOKEN_URI
      - N8N_OAUTH2_VERIFY_URI
      - N8N_OAUTH2_CLIENT_ID
      - N8N_OAUTH2_SECRET
      - N8N_AUTH_EXCLUDE_ENDPOINTS=css:font:fonts:fonts.css:js:rest
      - N8N_OAUTH2_SCOPES=profile
      - N8N_HOST=${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - N8N_PATH
      - WEBHOOK_URL=https://${DOMAIN_NAME}${N8N_PATH}
      - WEBHOOK_TUNNEL_URL=https://${DOMAIN_NAME}/
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ${DATA_FOLDER}/.n8n:/root/.n8n

I think you would need the ${N8N_PATH} in your Webhook URL as well but for this one I think you just need to set

VUE_APP_URL_BASE_API=https://${DOMAIN_NAME}${N8N_PATH}
1 Like