Describe the problem/error/question
When accessing my n8n instance hosted on an AWS EC2 server via my domain https://xxxx.cl, the interface loads but a “Connection lost” error appears, and in the server log I see “Invalid origin!” and in some cases “Origin header is missing”.
Also, when using Apache as a reverse proxy to localhost:5678, I sometimes get a “Connection refused” error if n8n is not listening properly.
I have a reverse proxy:
ServerName xxxx.cl
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/xxxx.cl/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxxx.cl/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ProxyPreserveHost On
ProxyRequests Off
# 🔧 WebSockets and HTTP
ProxyPass / http://127.0.0.1:5678/ retry=0
ProxyPassReverse / http://127.0.0.1:5678/
# 🔧 Specific WebSocket handling
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:5678/$1 [P,L]
# 🔧 Required headers
RequestHeader set Origin "https://xxxx.cl/"
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s"
RequestHeader set X-Forwarded-Host "%{HTTP_HOST}s"
RequestHeader set Host "%{HTTP_HOST}s"
ErrorLog ${APACHE_LOG_DIR}/n8n_error.log
CustomLog ${APACHE_LOG_DIR}/n8n_access.log combined
</VirtualHost>
And a PM2 ecosystem file:
module.exports = {
apps: [{
name: ‘n8n’,
script: ‘n8n’,
env: {
NODE_ENV: ‘production’,
N8N_RUNNERS_ENABLED: ‘true’,
N8N_PORT: 5678,
N8N_PROTOCOL: ‘http’,
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: ‘true’,
NODE_FUNCTION_ALLOW_EXTERNAL: ‘’,
N8N_PUSH_BACKEND: ‘websocket’,
N8N_HOST: ‘0.0.0.0’,
N8N_CORS_ORIGIN: ‘*’,
N8N_EDITOR_BASE_URL: ‘https://xxxx.cl’,
NODE_FUNCTION_ALLOW_BUILTIN: ‘’,
WEBHOOK_URL: ‘https://xxxx.cl/’,
WEBHOOK_TUNNEL_URL: ‘https://xxxx.cl/’,
N8N_SECURE_COOKIE: ‘true’
}
}]
};
What is the error message (if any)?
in n8n log
ResponseError: Invalid origin!
at Push.handleRequest (/home/ubuntu/.nvm/versions/node/v22.18.0/lib/node_modules/n8n/src/push/index.ts:143:10)
at /home/ubuntu/.nvm/versions/node/v22.18.0/lib/node_modules/n8n/src/push/index.ts:100:10
at Layer.handleRequest (/home/ubuntu/.nvm/versions/node/v22.18.0/lib/node_modules/n8n/node_modules/router/lib/layer.js:152:17)
at trimPrefix (/home/ubuntu/.nvm/versions/node/v22.18.0/lib/node_modules/n8n/node_modules/router/index.js:342:13)
at /home/ubuntu/.nvm/versions/node/v22.18.0/lib/node_modules/n8n/node_modules/router/index.js:297:9
at processParams (/home/ubuntu/.nvm/versions/node/v22.18.0/lib/node_modules/n8n/node_modules/router/index.js:582:12)
at next (/home/ubuntu/.nvm/versions/node/v22.18.0/lib/node_modules/n8n/node_modules/router/index.js:291:5)
at /home/ubuntu/.nvm/versions/node/v22.18.0/lib/node_modules/n8n/src/auth/auth.service.ts:106:18
apache logs
[proxy:error] (111)Connection refused: AH00957: http: attempt to connect to 127.0.0.1:5678 (localhost) failed
[proxy_http:error] HTTP: failed to make connection to backend: localhost
- n8n version: 1.104.2
- Database: SQLite (por defecto)
- n8n EXECUTIONS_PROCESS: own
- Running n8n via: npm + PM2 en servidor Ubuntu 22.04 en AWS EC2
- Operating system: Ubuntu 22.04 LTS