Traefik 2.x and GitLab Docker Setup Returning 404 for GitLab Service

53 Views Asked by At

I've set up GitLab using Docker and Traefik 2.11 as a reverse proxy, but when I try to access GitLab at https://gitlab.example.com, I get a 404 error. I'm using Docker Compose for both Traefik and GitLab configurations. Traefik is supposed to handle HTTPS requests and route them to GitLab, but it seems like the routing isn't working as expected.

version: '3'

services:
  traefik:
    image: traefik:v2.11
    container_name: "traefik"
    restart: always
    command:
      - "--api.insecure=true"
      - "--providers.docker"
      - "--providers.docker.exposedByDefault=false"
      - "--providers.docker.network=traefik_web"
      - "--entrypoints.http.address=:80"
      - "--entrypoints.http.http.redirections.entrypoint.to=https"
      - "--entrypoints.http.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.https.address=:443"
      - "--entrypoints.https.http.tls.certResolver=le"
      - "--certificatesresolvers.le.acme.tlschallenge=true"
      - "[email protected]"
      - "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./../letsencrypt:/letsencrypt
    networks:
      - web

networks:
  web:
    name: traefik_web

version: '3.7'

services:
  gitlab-main:
    image: 'gitlab/gitlab-ce:latest'
    hostname: "gitlab.skull-music.com"
    container_name: gitlab
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.skull-music.com'
    networks:
      - traefik_web
    labels:
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.gitlab.rule=Host(`gitlab.skull-music.com`)"
      - "traefik.http.routers.gitlab.entrypoints=https"
      - "traefik.http.routers.gitlab.tls=true"
      - "traefik.http.routers.gitlab.service=gitlab-main"
      - "traefik.http.services.gitlab-main.loadbalancer.server.port=80"
      - "traefik.http.routers.gitlab.tls.certResolver=le"


networks:
  traefik_web:
    name: traefik_web
    external: true

What I've tried:

  1. Ensuring DNS settings are correct.
  2. Checking Traefik and GitLab logs, but there are no obvious errors related to the 404.
  3. Verifying that the Traefik network traefik_web is correctly shared between Traefik and GitLab services.
  4. I added the line like suggested in the answers.
      - "traefik.http.routers.gitlab.tls.certResolver=le"

Questions:

Is there any misconfiguration in my Docker Compose files that could be causing this issue? How can I further debug the 404 error when accessing GitLab through Traefik? Any help or pointers would be greatly appreciated. Thank you!

2

There are 2 best solutions below

3
Teemu Risikko On

I think you are missing a certResolver from your service labels. You have this on your traefik command, but it needs to be included on the gitlab-main service too, like this:

      - "traefik.http.routers.gitlab.tls.certResolver=le"

From Traefik Documentation

Defining a certificate resolver does not result in all routers automatically using it. Each router that is supposed to use the resolver must reference it.

I tested on my own server, and without it I get the same 404 error.

0
sebastian kull On

Adding the lines nginx['listen_https'] = false and nginx['listen_port'] = 80 to the docker-copmpose.yml file effectively resolved my issue.

Without it the container stopped working after some time do to a RuntimeError related to acme_certificate.

Also i want mention that gitlab takes a while to start (in the case till it crashed 10 minutes)

version: '3.7'
services:

  gitlab-main:
    image: 'gitlab/gitlab-ce:latest'
    hostname: "gitlab.skull-music.com"
    container_name: gitlab
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.skull-music.com'
        nginx['listen_https'] = false
        nginx['listen_port'] = 80
    networks:
      - traefik_web
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.gitlab.rule=Host(`gitlab.skull-music.com`)"
      - "traefik.http.routers.gitlab.entrypoints=https"
      - "traefik.http.routers.gitlab.tls=true"
      - "traefik.http.routers.gitlab.service=gitlab-main"
      - "traefik.http.services.gitlab-main.loadbalancer.server.port=80"
      - "traefik.http.routers.gitlab.tls.certResolver=le"

networks:
  traefik_web:
    name: traefik_web
    external: true