N8n fails to connect to the internet via corporate proxy

Description

I deployed n8n in an internal corporate network where all internet connections must go through a proxy. However, n8n fails to connect to the internet when using the corporate network, while it works fine when switching to a mobile network.

I have tried multiple deployment methods, including:

  • Docker container
  • npm installation (bare metal Ubuntu 22.04 server)
  • n8n desktop app

Regardless of the method, n8n cannot connect to external APIs via the proxy.

n8n setup Information

  • **n8n version:**1.79.3
  • **Database (default: SQLite):**SQLite
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):**default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):**Docker, npm, desktop app
  • **Operating system:**Ubuntu 22.04 Server

Issue Details

I built a simple AI chatbot workflow that integrates with Azure OpenAI API. The API requests must go through the corporate proxy.

I have already set up the proxy correctly at multiple levels:
:heavy_check_mark: export HTTP_PROXY / HTTPS_PROXY (both globally and per user)
:heavy_check_mark: Configured npm & Node.js to use the correct proxy
:heavy_check_mark: Modified .bashrc, .npmrc, /etc/environment to persist settings
:heavy_check_mark: Tested with curl, wget — both work fine through the proxy

However, n8n fails to connect to the internet via the proxy, while other tools can.

Workflow Design

Error Logs

Error in handler N8nLlmTracing, handleLLMStart: TypeError: fetch failed
Connection error.
request to https://xxxapi.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=20xx-01-01-preview failed, reason: connect EHOSTUNREACH 20.xx.xx.xx:443

Steps Taken to Troubleshoot

  1. Tested network connection from within the n8n environment:

    • curl :white_check_mark: Works
    • wget :white_check_mark: Works
  2. Checked n8n’s proxy settings:

    • Manually set HTTP_PROXY and HTTPS_PROXY before starting n8n:
      HTTP_PROXY="http://xx.xx.com:xxxx" \
      HTTPS_PROXY="http://xx.xx.com:xxxx" \
      NODE_TLS_REJECT_UNAUTHORIZED=0 \
      n8n start
      
    • No improvement.
  3. Configured .npmrc, .bashrc, /etc/environment to persist proxy settings.

    • No improvement.
  4. Tested HTTP Request Node in n8n

    • Manually added http://xx.xx.com:xxxx under “Proxy” settings
    • Request still fails with EHOSTUNREACH error.
  5. Tried running n8n inside and outside Docker

    • Both npm and Docker deployments fail to use the proxy.
    • However, switching to mobile network immediately fixes the issue.

Expected Behavior

  • n8n should be able to make external API calls via the configured corporate proxy.

  • Other tools (curl, wget, npm) can already do this without issues.

Actual Behavior

  • n8n cannot connect to external APIs (e.g., https://api.openai.com) when behind the proxy.

  • Other applications in the same environment can connect just fine.


Additional Notes

  • This issue occurs regardless of whether I run n8n via npm, Docker, or desktop app.

  • Switching to a mobile network resolves the issue instantly, proving that the proxy is the root cause.

Thank You!

I appreciate any insights or fixes you can provide.
If there’s any debug mode or additional logs you need, let me know!

Here are a few things to double-check and try:

  1. Environment Variable Scope: Make absolutely sure the HTTP_PROXY and HTTPS_PROXY environment variables are being picked up by the n8n process itself. When starting n8n (especially via npm), set them directly in the terminal session before launching n8n. For Docker, ensure you’re passing them correctly in your docker run or docker-compose.yml.
  2. HTTP Request Node Proxy Setting: In your workflow, try explicitly setting the “Proxy” field in the HTTP Request node to your proxy URL (e.g., http://your-proxy-host:port). Test with a simple URL like https://httpbin.org/ip to isolate the issue.
  3. Proxy Authentication: Does your proxy require authentication? If so, make sure you’re including your username and password in the proxy URL (e.g., http://username:password@your-proxy-host:port) in both environment variables and the HTTP Request node setting.
  4. NODE_TLS_REJECT_UNAUTHORIZED=0 (Cautiously): While you’ve tried this, only use it for testing if you suspect SSL issues with your proxy. It’s not recommended for production.

If none of this works, double-check the n8n environment variable documentation to see if there are any other proxy-related settings.

Good luck! Let us know how it goes.

Did it work is some way?
I’m facing the same issue

1 Like

Same problem here.
All troubleshooting done so far are pointing to Axios (the web client) is not aware of the ‘CONNECT’ command used by proxy as well as the busybox wget implementation…

While many are moving to the Cloud, those who aren’t typically have sensitive data and often have their internet access restricted through a proxy server.
It’s surprising that n8n offers an on-premise version, claiming it helps ‘meet security standards’, yet fails to consider a basic security principle.

2 Likes

Hello,

Does your proxy allow connexion to AI model ? From my company I can access with proxy “user” but not with proxy “server”… security reason.

Did you try with your company proxy to use http node and reach a HTTPS website like https://google.com ? For me the problem was that my proxy is an http proxy and n8n seems to not like http proxy to access https website.

Come back to me if you can’t reach https website like google behind your proxy I have a solution (not easy if you are not technical)

Same issue I am facing,.

I can reach other sites from busy box pod after setting proxy and no_proxy… But, I can’t reach same url from http workflow component

For me the problem was that my proxy is an http proxy and n8n seems to not like http proxy to access https website.

This is clearly the problem we’re facing : when connecting to a https site through a http proxy, you need to use CONNECT to the proxy so it’ll tunnel client traffic to https site. And n8n is not doing this step !
I’ve done some tcpdump on the docker interface on my server :

  • from stock deployment, wget is not using CONNECT
  • after installing wget v1.25 from apk (using http repositories…) : wget is using CONNECT to reach https sites

Problem still present with n8n v1.90.2

Could you try this WF and tell me if it’s work ?

You could also see this post :

Cannot find module ‘axios’ [line 1]

VMError

Looks like I need to rebuild docker image with this module and try it

1 Like

Same here.
I upgraded n8n to v1.91.2 => same problem.
I also tried to upgrade axios to v1.9.0 inside container => same problem.

Stange axios is a default module in n8n (use by http node).

const axios = require(“axios”);
const { HttpsProxyAgent } = require(“https-proxy-agent”);
async function call() {
const url = “https://google.fr”;
const agent = new HttpsProxyAgent(“YOUR PROXY HERE”);
const res = await axios.get(url, { httpAgent:agent, httpsAgent:agent, proxy: false });
return res
}
result = await call();

The code above works for me…I’m currently in 1.90.1

Following my ENV vars (maybe it comes from the ENV var N8N_RUNNERS_ALLOW_PROTOTYPE_MUTATION

N8N_RUNNERS_GRANT_TOKEN: ‘xxxxxxxxxxxxxx’,
N8N_RUNNERS_TASK_BROKER_URI: ‘http://127.0.0.1:5679’,
N8N_RUNNERS_MAX_PAYLOAD: ‘1073741824’,
N8N_RUNNERS_MAX_CONCURRENCY: ‘10’,
PATH: ‘/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin’,
HOME: ‘/home/node’,
NODE_FUNCTION_ALLOW_BUILTIN: *,
NODE_FUNCTION_ALLOW_EXTERNAL: *,
N8N_RUNNERS_ALLOW_PROTOTYPE_MUTATION: ‘true’,
N8N_VERSION: ‘1.90.1’,
NODE_PATH: ‘/usr/local/lib/node_modules/n8n/dist/node_modules:/usr/local/lib/node_modules/n8n/node_modules:/usr/local/lib/node_modules:/usr/local/node_modules:/usr/node_modules:/node_modules’

I am getting same error Cannot find module ‘axios’ [line 1] in 1.91.2

Here is my ENV (with fresh container) :

N8N_DIAGNOSTICS_ENABLED=false
HTTPS_PROXY=hxxp://:@proxy:8080
N8N_HOST=server
no_proxy=host.docker.internal
NODE_VERSION=20.19.0
HOSTNAME=09e6e2177c77
YARN_VERSION=1.22.22
SHLVL=1
HOME=/root
https_proxy_license_server=hxxp://:@proxy:8080
N8N_PORT=5678
N8N_SSL_CERT=/files/ssl/self-signed/certificate.crt
N8N_SECURE_COOKIE=true
https_proxy=hxxp://:@proxy:8080
http_proxy=hxxp://:@proxy:8080
NODE_ICU_DATA=/usr/local/lib/node_modules/full-icu
TERM=xterm
N8N_SSL_KEY=/files/ssl/self-signed/private.key
GENERIC_TIMEZONE=Europe/Paris
N8N_TEMPLATES_ENABLED=false
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SHELL=/bin/sh
N8N_VERSION_NOTIFICATIONS_ENABLED=false
N8N_RELEASE_TYPE=stable
N8N_LOG_LEVEL=debug
PWD=/home/node
WEBHOOK_URL=hxxps://server:5678/
HTTP_PROXY=hxxp://:@proxy:8080
N8N_PROTOCOL=https
NODE_ENV=production
N8N_VERSION=1.91.2

http replaced with hxxp because “new users can only post 5 URLs” :slight_smile:
And here is the error details :

{
  "errorMessage": "Cannot find module 'axios' [line 1]",
  "errorDescription": "VMError",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "Code",
    "nodeType": "n8n-nodes-base.code",
    "nodeVersion": 2,
    "n8nVersion": "1.91.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "VMError: Cannot find module 'axios'",
      "    at Resolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:126:9)",
      "    at Resolver.resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:121:15)",
      "    at resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:317:21)",
      "    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:490:11)",
      "    at requireImpl (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:90:19)",
      "    at require (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:171:10)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:1:112",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:18:2",
      "    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:490:11)",
      "    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:497:23)"
    ]
  }
}

And when using the HTTP Request module :

Sorry, limited to 3 reply cause I’m a new user :frowning: So I edit this one as I can’t reply to @Kent1 .

Hi @Kent1,
Here is the new error with the env var added :

{
  "errorMessage": "Cannot read properties of undefined (reading 'href') [line 6]",
  "errorDescription": "TypeError",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "Code",
    "nodeType": "n8n-nodes-base.code",
    "nodeVersion": 2,
    "n8nVersion": "1.91.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "TypeError: Cannot read properties of undefined (reading 'href')",
      "    at new HttpsProxyAgent (/usr/local/lib/node_modules/n8n/node_modules/https-proxy-agent/dist/index.js:67:71)",
      "    at ReadOnlyHandler.construct (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:503:11)",
      "    at call (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:6:17)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:10:16",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:18:2",
      "    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:490:11)",
      "    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:497:23)",
      "    at JavaScriptSandbox.runCodeAllItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox.js:73:39)",
      "    at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:155:31)",
      "    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:687:50)"
    ]
  }
}

Can you try to set this env var

NODE_FUNCTION_ALLOW_EXTERNAL=*

Hi @Kent1,
Here is the new error with the env var added :

{
  "errorMessage": "Cannot read properties of undefined (reading 'href') [line 6]",
  "errorDescription": "TypeError",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "Code",
    "nodeType": "n8n-nodes-base.code",
    "nodeVersion": 2,
    "n8nVersion": "1.91.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "TypeError: Cannot read properties of undefined (reading 'href')",
      "    at new HttpsProxyAgent (/usr/local/lib/node_modules/n8n/node_modules/https-proxy-agent/dist/index.js:67:71)",
      "    at ReadOnlyHandler.construct (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:503:11)",
      "    at call (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:6:17)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:10:16",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:18:2",
      "    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:490:11)",
      "    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:497:23)",
      "    at JavaScriptSandbox.runCodeAllItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox.js:73:39)",
      "    at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:155:31)",
      "    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:687:50)"
    ]
  }
}

Replace the line 6

const agent = new HttpsProxyAgent(“URL_OF_YOUR_PROXY”);

Hi @Kent1,

It works when the proxy URL is hardcoded !!
It seems like axios isn’t picking up (or can’t find) proxy’s env var…

So you have the same problem as me

To solved it I build my dockerimage with Dockerfile I use sed command to add this piece of code in Node request-helper-functions.ts.js file.

First it check if I need to use proxy env (with a boolean) and if yes I use https-proxy-agent to set proxy var.

const no_proxy = process.env.no_proxy.split(',');
    var use_proxy = true;
    for (let i = 0; i < no_proxy.length; i++){
        if (requestObject.uri.includes(no_proxy[i]) ) {
            use_proxy = false;
        }
    }
    if (use_proxy) {    
        const { HttpsProxyAgent } = require("https-proxy-agent");
        const agent = new HttpsProxyAgent(process.env.http_proxy);
        axiosConfig.httpAgent = agent;
        axiosConfig.httpsAgent = agent;
        axiosConfig.proxy = false;
    }
1 Like