N8n nginx reverse proxy as sublocation

Hey i have nginx reverse proxy on my server and it serves few websites on /, /blog, /blahblahblah
and i want to serve n8n on /_apps/n8n.
1st request seems to work because in network i can see We're sorry but the n8n Editor-UI doesn't work properly without JavaScript enabled. Please enable it to continue.
but other requests has no prefix /_apps/n8n . for example /assets/n8n-def62baf.css has no /_apps/n8n prefix and nginx redirects it to default 404 page.

nginx:

    location /_apps/n8n {
      proxy_buffering off;
      proxy_cache off;
      proxy_http_version 1.1;
      chunked_transfer_encoding off;
      proxy_set_header Connection '';
      proxy_pass "http://127.0.0.1:5678";
    }

docker cmd:
docker run -d -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n

I tried to set env vars like N8N_HOST etc but it didnt work. maybe i set wrong values.

Can someone help me with this?

Hey @lumbaq,

Welcome to the community :cake:

Have you tried setting N8N_PATH and N8N_HOST? looking at your nginx config you will probably run into issues with websockets as well but that is something to work out once you at least get things loading.

EDIT: worked! but there is another problem. everywhere 401

Hey @lumbaq

That could be because websockets are not configured, Try the config below and see if that helps. You may need to consult your server admin / nginx support team to confirm.

location /_apps/n8n {
      proxy_http_version 1.1;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Upgrade $http_upgrade;
      proxy_pass "http://127.0.0.1:5678";
    }

nothing changed :frowning:

It may need tweaking, I think that is normally what works for Websockets but you may need to do something else for your environment.

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