7 min read

Ollama Connection Refused: How to Fix Port 11434

Ollama listens only on 127.0.0.1 by default, so Docker apps and other machines get connection refused. Find your setup, fix the address, and keep it secure.

By Cogniq Labs ResearchEvidence policy

InferenceAgents in Production
Isometric illustration of two separate platforms joined by a broken cable, with a gap marked in red between an application block and a model server block.

"Connection refused" on port 11434 means nothing is listening at the address your app is trying. Usually Ollama is running but listens only on 127.0.0.1, which an app inside a Docker container or on another computer cannot reach. The fix is to make Ollama listen on the right address and to give your app the right URL. Which URL depends on where the app and Ollama run.

Work through the steps in order. Each one takes a minute.

Step 1: is Ollama running at all?

On the machine that runs Ollama:

curl http://localhost:11434/api/version

A short version number means Ollama is up and reachable locally. If this fails, nothing else matters yet: start the Ollama application or service, and check its log for why it stopped. On Linux with systemd, that is journalctl -u ollama. If the model crashes when you use it, that is a different error, covered in reading Ollama's "process has terminated" error.

Step 2: what address is it listening on?

Ollama's FAQ says it binds 127.0.0.1 port 11434 by default. The Open WebUI troubleshooting page gives the commands to check:

# Linux
ss -tlnp | grep 11434

# Windows
netstat -an | findstr 11434
Output shows Meaning
127.0.0.1:11434 Only this machine, and only outside containers, can connect
0.0.0.0:11434, *:11434 or [::]:11434 Listening on all network interfaces
Nothing Ollama is not listening on that port

Step 3: pick the right URL for your setup

The most common mistake is writing localhost in an app that runs somewhere else. Inside a container, localhost means the container. The n8n documentation explains the cases, and they apply to any app:

Where the app runs Where Ollama runs URL to use Ollama needs
On the same machine, no Docker Same machine http://localhost:11434 Default is fine
In Docker On the host http://host.docker.internal:11434 OLLAMA_HOST=0.0.0.0
On the host In Docker http://localhost:11434 Publish with -p 11434:11434
In Docker In another container http://<ollama-container-name>:11434 Both on one Docker network
On another computer Any http://<server-ip>:11434 OLLAMA_HOST=0.0.0.0 and a firewall rule

The official Ollama images are already configured to listen on all interfaces inside the container, according to n8n's page, so publishing the port is what matters there.

Step 4: set OLLAMA_HOST correctly

Set it where your Ollama server actually reads its environment, then restart. A variable exported in your terminal does not reach a service started by the system.

Linux with systemd. Run systemctl edit ollama.service and add:

[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"

Then:

sudo systemctl daemon-reload
sudo systemctl restart ollama

Open WebUI's page names the usual reasons the address stays at 127.0.0.1: a missing [Service] line, a skipped daemon-reload or a skipped restart.

Windows. Quit Ollama from the taskbar, add OLLAMA_HOST to your user environment variables, then start Ollama again from the Start menu.

macOS application. Run launchctl setenv OLLAMA_HOST "0.0.0.0:11434", then restart Ollama.

Run the check from step 2 again to confirm the address changed.

Step 5: Docker on Linux

Docker Desktop resolves host.docker.internal for you. Docker Engine on Linux does not, so add the mapping when you create the container, as Docker's run reference describes:

docker run -d --add-host=host.docker.internal:host-gateway ...

In Compose, the equivalent is an extra_hosts entry. Then test from inside the app's container, which is the only test that matters:

docker exec open-webui curl --fail --show-error --silent --max-time 5 \
  http://host.docker.internal:11434/api/version

A version number means the container can reach Ollama. If the name does not resolve, the --add-host mapping is missing. If it resolves but the request fails, check what Ollama is listening on and whether the host firewall allows traffic from the Docker network to port 11434.

The host network option. --network=host lets the container use the host's network directly, so http://127.0.0.1:11434 works. Know the side effects: Docker ignores published ports in this mode, and on Docker Desktop host networking needs version 4.34 or later and must be enabled in settings.

Step 6: check the URL itself

Small mistakes produce confusing errors. Open WebUI's page lists these:

What was typed What happens
192.168.1.5:11434 No http://, so the request fails before it is sent
http://192.168.1.5 Port 80 is used instead of 11434
http://localhost:11434/api The app asks for /api/api/... and fails

An Ollama base URL is http://host:port with nothing after the port.

One more trap: some tools resolve localhost to the IPv6 address ::1, while Ollama listens on the IPv4 address. If a tool on the same machine refuses to connect to localhost but curl works, try http://127.0.0.1:11434.

Keep the port private

This part is easy to skip and matters. Open WebUI's documentation notes that Ollama's local API does not require authentication, so with OLLAMA_HOST=0.0.0.0 any device that can reach the host on port 11434 can use your models. On a shared or public network:

  • Allow port 11434 only from the machines that need it, with the host firewall.
  • Or keep Ollama and the app on one Docker network and do not publish the port at all. Open WebUI's own Compose file does this.
  • Never forward 11434 from your router to the internet.

If your app is a web page calling Ollama from the browser, a blocked request is often not a refused connection but a cross-origin block. The FAQ says Ollama allows requests from 127.0.0.1 and 0.0.0.0 by default, and OLLAMA_ORIGINS adds others. For Open WebUI this does not apply, because it calls Ollama from its server, not from your browser.

A setup that avoids the problem: Compose on one network

If you are starting fresh, run both services in one Compose project. Containers on the same Compose network reach each other by service name, so there is no localhost confusion, no host.docker.internal, and no port open to your network. A minimal shape:

services:
  ollama:
    image: ollama/ollama
    volumes:
      - ollama:/root/.ollama
  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    ports:
      - "3000:8080"
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
    volumes:
      - open-webui:/app/backend/data
volumes:
  ollama:
  open-webui:

Note that the ollama service has no ports entry. Only Open WebUI is published, which matches what the project's own Compose file does. Treat this as a starting point: add GPU access for the Ollama service if you have one, as the CPU and GPU guide describes.

Reaching a remote server without opening the port

To use Ollama on another machine from your laptop, an SSH tunnel avoids exposing anything:

ssh -L 11434:localhost:11434 user@your-server

While that session is open, http://localhost:11434 on your laptop reaches Ollama on the server, which can keep listening on 127.0.0.1. Stop any local Ollama first, or pick a different local port, such as -L 11500:localhost:11434, and point your app at port 11500.

Connecting n8n to a remote Ollama

For a remote instance that sits behind authentication, n8n's documentation says its Ollama Model node supports a bearer token, for example when Open WebUI is the proxy in front of Ollama. Put both the remote address and the key in the Ollama credentials. That is a different setup from the local cases above: the address is your proxy's, not port 11434 on the server, and a rejected key shows up as an authorisation error, not a refused connection.

If Ollama answers but cannot download a model, that is a different fault: see Ollama pull model manifest errors.

Behind a proxy

If you put Nginx in front of Ollama, the FAQ's example forwards requests and sets the Host header to localhost:11434. It also warns against setting HTTP_PROXY for Ollama: Ollama downloads models over HTTPS only, and setting HTTP_PROXY may interrupt client connections to the server. Use HTTPS_PROXY for downloads.

When it connects but still fails

Reaching Ollama and getting an answer are separate things:

  • A 503 error means the server is overloaded and refusing requests. The FAQ says OLLAMA_MAX_QUEUE sets how many can wait.
  • Open WebUI lists models but chats fail. Checking a connection only asks for the version and model list. Running a model is a separate request, so test with ollama run <model> on the Ollama machine.
  • A memory error means the model does not fit: see why Ollama runs out of memory.
  • Very slow replies are a performance problem: see why Ollama is slow on the GPU or on the CPU.

Checklist

  1. curl http://localhost:11434/api/version on the Ollama machine.
  2. Check the listening address with ss or netstat.
  3. Choose the URL from the setup table.
  4. Set OLLAMA_HOST in the right place and restart.
  5. On Linux Docker, add --add-host=host.docker.internal:host-gateway.
  6. Test with curl from inside the app's container.
  7. Firewall port 11434.

What we do not know

We have not tested every combination of operating system, Docker version and application. Defaults and screens change between releases, so check the current documentation for your app. Corporate networks, VPNs and security software can block connections in ways none of these steps show, and the container-to-host test is the quickest way to find out where the break is.

Sources

  1. Ollama FAQ — Ollama
  2. Server Connection Errors — Open WebUI
  3. Ollama Model node: common issues — n8n
  4. docker container run reference — Docker

Frequently asked questions

Why does Ollama say connection refused on port 11434?

Either Ollama is not running, or your app is trying an address where Ollama is not listening. By default it listens only on 127.0.0.1, so an app inside a Docker container or on another computer cannot reach it, because localhost there means that container or computer.

How do I make Ollama listen on 0.0.0.0?

Set the OLLAMA_HOST environment variable to 0.0.0.0:11434 and restart Ollama. On Linux with systemd, add it with systemctl edit ollama.service, then reload and restart. On Windows, set a user environment variable and restart the app. On macOS, use launchctl setenv and restart the app.

How does an app in Docker connect to Ollama on the host?

Use http://host.docker.internal:11434 as the address and make Ollama listen on 0.0.0.0. Docker Desktop resolves that name automatically. On Linux Docker Engine, add --add-host=host.docker.internal:host-gateway when creating the container.

Is it safe to set OLLAMA_HOST to 0.0.0.0?

Only with a firewall in front of it. Ollama's local API has no authentication, so any device that can reach port 11434 can use it. Limit access to the machines that need it, or keep Ollama on a private Docker network without publishing the port.

Why does Open WebUI connect but show no models?

Open WebUI lists only the models returned by the Ollama addresses it is configured with. If the list differs from ollama list, the two are usually talking to different installs, for example a native Ollama and an Ollama container, each with its own models.

Related reading