n8n frontend API connectivity issue on Railway - HTTPS domain configuration
icaroo77
HOBBYOP

7 days ago

I'm running n8n on Railway with a PostgreSQL database and Redis, deployed to a public HTTPS domain (n8n-main-instance-production-db47.up.railway.app).

The server backend is running correctly and connected to Postgres + Redis (logs show successful initialization). However, the frontend cannot connect to the API and shows "Error connecting to n8n - Could not connect to server."

What I've tried:

Observations:

  • Frontend page loads (all assets 200 OK)
  • Zero API requests being made to /api/* endpoints
  • Browser console: "Failed to initialize settings store ResponseError: Can't connect to n8n"
  • Backend deployment logs show successful database connection

Service Details:

  • Service ID: 5aa1dd21-dafe-4c4f-8bf8-d147e78997ee
  • Docker image: n8nio/n8n:latest
  • Public domain: n8n-main-instance-production-db47.up.railway.app
  • Connected to Postgres and Redis
  • Volume mount: /n8n/volume

The issue appears to be that n8n's frontend is pre-compiled in the Docker image and environment variables aren't being injected into the compiled JavaScript. Could Railway support help with the correct configuration or deployment approach?

$10 Bounty

1 Replies

Railway
BOT

7 days ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway 7 days ago


dash2dollas
FREE

7 days ago

This is a classic and frustrating issue with n8n on Railway. The root cause is that the VUE_APP_URL_BASE_API environment variable, which controls where the frontend looks for the backend API, is not configurable in the standard n8n Docker image.

You've set all the right backend variables (N8N_EDITOR_BASE_URL, WEBHOOK_URL, etc.), but the pre-built frontend in the Docker image is hardcoded to look for the API at /rest on the same domain. Since Railway serves your app from a subdomain, this relative path fails, resulting in the "Could not connect to server" error.

Here are three ways to fix it, ranked from most to least recommended:

  1. Build a Custom Docker Image (The Correct Fix)

This is the only way to properly set the API base URL. The n8n documentation explicitly states that to change this, you must manually build the n8n-editor-ui package.

You can do this by creating a Dockerfile in your project:

FROM n8nio/n8n:latest AS builder

# Build the UI with the correct API URL
ENV VUE_APP_URL_BASE_API=https://n8n-main-instance-production-db47.up.railway.app/
RUN cd /usr/local/lib/node_modules/n8n/node_modules/n8n-editor-ui && \
    npm run build

FROM n8nio/n8n:latest
COPY --from=builder /usr/local/lib/node_modules/n8n/node_modules/n8n-editor-ui/dist /usr/local/lib/node_modules/n8n/node_modules/n8n-editor-ui/dist

This builds a new image where the frontend is correctly configured to point to your Railway URL.

  1. Use a Reverse Proxy (Quick Workaround)

If building a custom image isn't an option, you can deploy a small reverse proxy service (like a CORS proxy) alongside your n8n instance. This proxy sits between your browser and n8n, forwarding requests to the correct API endpoint.

Deploy a simple proxy service on Railway with these environment variables:

· TARGET: https://n8n-main-instance-production-db47.up.railway.app

· ALLOWED_ORIGIN: * (for testing)

Then, access your n8n instance through the proxy's URL instead of directly. The proxy will handle the routing and CORS issues.

  1. Double-Check Your Current Variables

Before going with the more complex solutions, ensure your existing variables are perfectly correct:

· N8N_EDITOR_BASE_URL: Must be exactly https://n8n-main-instance-production-db47.up.railway.app (no trailing slash).

· WEBHOOK_URL: Must be exactly https://n8n-main-instance-production-db47.up.railway.app/ (with trailing slash).

· N8N_PROTOCOL: https

· N8N_HOST: n8n-main-instance-production-db47.up.railway.app

Also, add these to rule out CORS issues:

· N8N_DEFAULT_CORS: TRUE

· N8N_CORS_ALLOW_ORIGIN: https://n8n-main-instance-production-db47.up.railway.app

After making these changes, do a full redeploy and clear your browser cache again.

Summary

Approach Effort Best For

Build Custom Image Medium Long-term, production-ready solution

Use Reverse Proxy Low Quick fix, testing, or temporary workaround

Check Variables Minimal First step to rule out simple misconfigurations

My recommendation: Go with Option 1 (Build Custom Image). It's the proper way to solve this and will save you from future headaches. The official n8n documentation confirms this is the required approach for changing the frontend's API base URL..


Welcome!

Sign in to your Railway account to join the conversation.

Loading...