Authentication required to access /rest/login?

Describe the problem/error/question

I’ve setup n8n with npm, using websocket push backend and user management.

As I’m logged in on one of my used browsers, I can access and use n8n.

But if I open n8n in a new private tab, I only see the red loading spinner when I would expect the login screen.
The network logof the browser says, that while accessing /rest/login n8n responded with

{
    "code": 401,
    "message": "Not logged in"
}

My nginx reverse proxy configuration looks like this:

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

   location /rest {
     proxy_pass http://127.0.0.1:5678;
     proxy_ssl_verify off;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection 'Upgrade';
     proxy_set_header Host $host;
     proxy_ssl_server_name on;
   }

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

My n8n systemd service unit looks like this:

[Unit]
Description=n8n - Easily automate tasks across different services.
After=network.target
[Service]
Type=simple
User=www-data
ExecStart=/usr/bin/n8n
Restart=on-failure
Environment=N8N_HOST="n8n.***************"
Environment=N8N_METRICS=true
Environment=N8N_VERSION_NOTIFICATIONS_ENABLED=false
Environment=N8N_DIAGNOSTICS_ENABLED=false
Environment=N8N_PROTOCOL=https
Environment=WEBHOOK_URL="https://n8n.***************/"
Environment=NODE_ENV=production
Environment=NODE_TLS_REJECT_UNAUTHORIZED=0
Environment=NODE_OPTIONS="--max-old-space-size=16384"
Environment=GENERIC_TIMEZONE="Europe/Berlin"
Environment=N8N_LOG_OUTPUT=console
Environment=N8N_LOG_LEVEL=debug
Environment=N8N_PAYLOAD_SIZE_MAX=1024
Environment=DB_TYPE=postgresdb
Environment=DB_POSTGRESDB_DATABASE="n8n"
Environment=DB_POSTGRESDB_USER="n8n"
Environment=DB_POSTGRESDB_PASSWORD="***************"
Environment=EXECUTIONS_DATA_PRUNE=true
Environment=EXECUTIONS_DATA_MAX_AGE=5
Environment=NODE_FUNCTION_ALLOW_EXTERNAL=he,crypto-js
[Install]
WantedBy=multi-user.target

Do you see any issue here?

Information on your n8n setup

  • n8n version: 1.05
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Ubuntu LTS

Hey @mnebel,

I suspect the issue is with your nginx config, Can you try something like the below and let me know if that works.

server {
  listen 443 ssl;
  server_name n8n.my_domain.tld;
  location / {
    proxy_pass http://127.0.0.1:5678;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Upgrade $http_upgrade;
    proxy_http_version 1.1;
  }
  ssl_certificate # removed
  ssl_certificate_key # removed
}
1 Like

Hi @Jon,

thank you for your reply.

Actually the issue seem to have existed in 1.0.5 and was fixed in 1.2.0 with fix(core): Fix WebSocket close codes · n8n-io/n8n@a8bfb46 · GitHub.

I have now updated to the latest 1.3.0 and the issue is gone!

Thank you anyway!

1 Like

Hey @mnebel,

Even better :slight_smile:

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