Nginx connection refused

As I’m trying to setup the drone server, I migrated the local nginx installation to docker so I can proxy drone with it.
I did the configuration as in the documentation (http://docs.drone.io/setup-with-nginx/), but it just doesn’t let me.
Since I’m somewhat new setting up stuff I’m not too sure if it’s an issue with my nginx configuration or with my drone setup.

Anyways, I get the following error from the access-log from nginx:

2018/08/28 16:03:42 [error] 7#7: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: ci.prefix.moe, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "ci.prefix.moe"
2018/08/28 16:03:42 [error] 7#7: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: ci.prefix.moe, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: "ci.prefix.moe", referrer: "http://ci.prefix.moe/"

The browser itself receives a 502 Bad Gateway from nginx then.

docker-compose.yaml

version: '2'

services:
  drone-server:
    image: drone/drone:0.8

    ports:
      - 8000
      - 9000
    volumes:
      - /srv/drone:/var/lib/drone/
    restart: always
    environment:
      - DRONE_OPEN=true
      - DRONE_HOST=http://ci.prefix.moe
      - DRONE_GITHUB=true
      - DRONE_GITHUB_CLIENT=${DRONE_GITHUB_CLIENT}
      - DRONE_GITHUB_SECRET=${DRONE_GITHUB_SECRET}
      - DRONE_SECRET=${DRONE_SECRET}

  drone-agent:
    image: drone/agent:0.8

    command: agent
    restart: always
    depends_on:
      - drone-server
    volumes:
      - /srv/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=drone-server:9000
      - DRONE_SECRET=${DRONE_SECRET}

My nginx-configuration for it:

server {
    listen 80;
    server_name ci.prefix.moe;

    location / {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;

        proxy_pass http://127.0.0.1:8000;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_buffering off;

        chunked_transfer_encoding off;
    }
}

Since I’m somewhat new setting up stuff I’m not too sure if it’s an issue with my nginx configuration or with my drone setup.

I think this is something you could verify by checking if you can access Drone directly (e.g. curl localhost:8000). If not, then you know the problem is with your Drone configuration. If yes, then you can assume the problem is with Nginx.

However, I do think the problem is with your port configuration:

services:
  drone-server:
    image: drone/drone:0.8

-   ports:
-     - 8000
-     - 9000
+   ports:
+     - 8000:8000
+     - 9000:9000

You should map the host and container port, otherwise Docker chooses an ephemeral host port at random, which would explain why nginx is unable to connect.

I should point out that there is no need to put a reverse proxy in front of Drone (unless you are using a shared server with multiple websites). Drone supports native TLS and Lets Encrypt and does not gain any performance or stability benefits from having a reverse proxy in front of it.

1 Like

Ah, explains a lot!
Now after fixing the port definition and properly restarting it (docker-compose down to remove the previously created network binding) it works :smiley:

Thanks a lot!