Gitea just returns a 404

SOLUTION (u/mrrichardcranium)

Change

  • "traefik.http.routers.git.loadbalancer.server.port=3000"

to

  • "traefik.http.services.git.loadbalancer.server.port=3000"

_____________________________________________________________________________

Since their forum seems to be rather slow in answering I hope someone over here can help me ;)

I'm trying to run Gitea behind a Traefik v2 proxy, but all I get is a 404. My config is

version: '3'

services:
  db:
    image: mariadb:latest
    container_name: git_db
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_GIT_DB}
      - MYSQL_USER=${MYSQL_GIT_USER}
      - MYSQL_PASSWORD=${MYSQL_GIT_PASSWORD}
    volumes:
      - ${DOCKERDIR}/git//db/:/var/lib/mysql
    networks:
      - internal

  git:
    image: gitea/gitea:latest
    volumes:
      - /mnt/data-storage/git-repositories:/data/git/repositories
      - ${DOCKERDIR}/git/gitea:/data
    ports:
#      - "3000:3000"
      - "2222:22"
    depends_on:
      - db
    restart: always
    environment:
      - DB_TYPE=mysql
      - DB_HOST=git_db
      - DB_NAME=${MYSQL_GIT_DB}
      - DB_USER=${MYSQL_GIT_USER}
      - DB_PASSWD=${MYSQL_GIT_PASSWORD}
      - DISABLE_SSH=true
      - SSH_DOMAIN=git.${DOMAIN_JS}
    labels:
      - "traefik.http.routers.git.rule=Host(`git.${DOMAIN_JS}`)"
      - "traefik.http.routers.git.tls=true"
      - "traefik.http.routers.git.tls.certresolver=le"
      - "traefik.http.routers.git.entrypoints=https"
      - "traefik.http.routers.git.loadbalancer.server.port=3000"
    networks:
      - external
      - internal

networks:
  external:
    external: true
  internal:
    external: false

I'd really love your help, as I need to complete this setup rather sooner than later...

Posted Mar 21, 2020, 11:53 AM UTC · edited

312
klutch2013•

I don't use the traefik reverse proxy but could it be that you have ports 3000:3000 commented out but your label is telling traefik to use 3000?

Also what are the docker logs come out of git?

2
fideli_•

That shouldn't be a problem. If Traefik works properly, the forwarding port 3000 from the host isn't required since Traefik would proxy it on the internal Docker network that both containers live on. I have commented out port forwards in my docker-compose files as well. I use them at first without Traefik to test the container. Once Traefik works, I comment out the port.

1
klutch2013•

Thanks for the info. I do t use Traefik so I wasn't sure.

2
von_AlenbergOP•

Well, that's the sad part, the logs don't say anything...

Starting git_db ... done
Starting git_git_1 ... done
Attaching to git_db, git_git_1
db_1   | 2020-03-21 16:16:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.12+maria~bionic started.
db_1   | 2020-03-21 16:16:02+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1   | 2020-03-21 16:16:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.12+maria~bionic started.
db_1   | 2020-03-21 16:16:02 0 [Note] mysqld (mysqld 10.4.12-MariaDB-1:10.4.12+maria~bionic) starting as process 1 ...
db_1   | 2020-03-21 16:16:02 0 [Note] InnoDB: Using Linux native AIO
db_1   | 2020-03-21 16:16:02 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1   | 2020-03-21 16:16:02 0 [Note] InnoDB: Uses event mutexes
db_1   | 2020-03-21 16:16:02 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1   | 2020-03-21 16:16:02 0 [Note] InnoDB: Number of pools: 1
db_1   | 2020-03-21 16:16:02 0 [Note] InnoDB: Using SSE2 crc32 instructions
db_1   | 2020-03-21 16:16:02 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: Completed initialization of buffer pool
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: 10.4.12 started; log sequence number 61044; transaction id 21
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1   | 2020-03-21 16:16:03 0 [Note] Plugin 'FEEDBACK' is disabled.
db_1   | 2020-03-21 16:16:03 0 [Note] Server socket created on IP: '::'.
db_1   | 2020-03-21 16:16:03 0 [Warning] 'proxies_priv' entry '@% root@55f9a817a658' ignored in --skip-name-resolve mode.
db_1   | 2020-03-21 16:16:03 0 [Note] InnoDB: Buffer pool(s) load completed at 200321 16:16:03
db_1   | 2020-03-21 16:16:03 0 [Note] Reading of all Master_info entries succeeded
db_1   | 2020-03-21 16:16:03 0 [Note] Added new Master_info '' to hash table
db_1   | 2020-03-21 16:16:03 0 [Note] mysqld: ready for connections.
db_1   | Version: '10.4.12-MariaDB-1:10.4.12+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
git_1  | Server listening on :: port 22.
git_1  | Server listening on 0.0.0.0 port 22.
git_1  | 2020/03/21 16:16:03 cmd/web.go:107:runWeb() [I] Starting Gitea on PID: 17
git_1  | 2020/03/21 16:16:03 ...dules/setting/git.go:93:newGit() [I] Git Version: 2.24.1, Wire Protocol Version 2 Enabled
git_1  | 2020/03/21 16:16:03 routers/init.go:88:GlobalInit() [T] AppPath: /app/gitea/gitea
git_1  | 2020/03/21 16:16:03 routers/init.go:89:GlobalInit() [T] AppWorkPath: /app/gitea
git_1  | 2020/03/21 16:16:03 routers/init.go:90:GlobalInit() [T] Custom path: /data/gitea
git_1  | 2020/03/21 16:16:03 routers/init.go:91:GlobalInit() [T] Log path: /data/gitea/log
git_1  | 2020/03/21 16:16:03 ...dules/setting/log.go:233:newLogService() [I] Gitea v1.12.0+dev-31-gb3f4f812d built with GNU Make 4.2.1, go1.14.1 : bindata, sqlite, sqlite_unlock_notify
git_1  | 2020/03/21 16:16:03 ...dules/setting/log.go:276:newLogService() [I] Gitea Log Mode: Console(Console:info)
git_1  | 2020/03/21 16:16:03 ...les/setting/cache.go:70:newCacheService() [I] Cache Service Enabled
git_1  | 2020/03/21 16:16:03 ...les/setting/cache.go:81:newCacheService() [I] Last Commit Cache Service Enabled
git_1  | 2020/03/21 16:16:03 ...s/setting/session.go:63:newSessionService() [I] Session Service Enabled
git_1  | 2020/03/21 16:16:03 routers/init.go:128:GlobalInit() [I] SQLite3 Supported
git_1  | 2020/03/21 16:16:03 routers/init.go:47:checkRunMode() [I] Run Mode: Development
git_1  | 2020/03/21 16:16:03 cmd/web.go:161:runWeb() [I] Listen: http://0.0.0.0:3000
git_1  | 2020/03/21 16:16:03 ...s/graceful/server.go:55:NewServer() [I] Starting new server: tcp:0.0.0.0:3000 on PID: 17

Also checked the traefik-logs, no info there. Traefik picks up the container event just fine.

1
klutch2013•

What is the traefik access logs say when you try and access git? That should give you more information as to where traefik is trying to get the website, and why it's giving the 404.

1
g-a-c•

Can you use environment variables in labels like that? Also, should they be backticks or single quotes? Also what does your Traefik config look like?

1
von_AlenbergOP•

Yes, the variables and quotes are OK, I use it the same way in many other containers.

Here is my traefik config:

version: "3"

networks:
  external:
    external : true

services:
  traefik:
    container_name: traefik
    restart: always
    image: traefik:latest
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    environment:
      - CLOUDFLARE_EMAIL=${CF_API_EMAIL}
      - CLOUDFLARE_API_KEY=${CF_API_KEY}
      - CF_DNS_API_TOKEN=${CF_DNS_API_TOKEN}
      - CF_ZONE_API_TOKEN=${CF_ZONE_API_TOKEN}
    volumes:
      - ${DOCKERDIR}/traefik/letsencrypt/:/letsencrypt:rw
      - /var/run/docker.sock:/var/run/docker.sock:ro
    command:
      # All entrypoints
      - --entrypoints.http.address=:80
      - --entrypoints.https.address=:443
      # Docker provider
      - --providers.docker.exposedByDefault=true
      - --providers.docker.endpoint=unix:///var/run/docker.sock
      - --providers.docker.network=external
      # Use of API
      - --api
      # Better logging
      - --log.level=DEBUG
      # Creating LE certs
#      - --certificatesResolvers.le.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory
      - --certificatesResolvers.le.acme.email=${LE_MAIL}
      - --certificatesResolvers.le.acme.storage=acme.json
      - --certificatesResolvers.le.acme.dnschallenge=true
      - --certificatesResolvers.le.acme.dnsChallenge.provider=cloudflare
      - --certificatesResolvers.le.acme.dnsChallenge.delayBeforeCheck=0
      # No SSL communication between traefik <-> apps
#      - --serverstransport.insecureskipverify=true
    labels:
      # Middleware for http redirect
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      - "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.routers.redirs.entrypoints=http"
      - "traefik.http.routers.redirs.middlewares=redirect-to-https"
      # Traefik dashboard available
      - "traefik.http.routers.traefik.rule=Host(`traefik.${DOMAIN_JS}`)"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.tls.certresolver=le"
      - "traefik.http.routers.traefik.entrypoints=https"
      - "traefik.http.routers.traefik.middlewares=sts_headers"
      # Set STS-header for security
      - "traefik.http.middlewares.sts_headers.headers.stsSeconds=15552000"
      - "traefik.http.middlewares.sts_headers.headers.stsIncludeSubdomains=True"
      - "traefik.http.middlewares.sts_headers.headers.stsPreload=true"
      # CalDAV / CardDAV discovery
      - "traefik.http.middlewares.dav_discovery.replacepathregex.regex=^/.well-known/(card|cal)dav"
      - "traefik.http.middlewares.dav_discovery.replacepathregex.replacement=/remote.php/dav/"
      # Webfinger discovery
      - "traefik.http.middlewares.webfinger.replacepathregex.regex=^/.well-known/webfinger"
      - "traefik.http.middlewares.webfinger.replacepathregex.replacement=/public.php?service=webfinger"
    networks:
      - external
  
  my-app:
    image: containous/whoami:v1.3.0
    labels:
      - traefik.http.routers.my-app.rule=Host(`whoami.${DOMAIN_JS}`)
      - traefik.http.routers.my-app.tls=true
      - traefik.http.routers.my-app.tls.certresolver=le
      - traefik.http.routers.my-app.entrypoints=https
    networks:
      - external
1
1205a70636•

Have you tried enabling the traefik api dashboard and see what is going on there?

1
IrgendwasMitH•

Can you add this traefik label:

"traefik.docker.network=external"

and report back?

1
mrrichardcranium•

You have no services label.

Change
- "traefik.http.routers.git.loadbalancer.server.port=3000"

to
- "traefik.http.services.git.loadbalancer.server.port=3000"

1
von_AlenbergOP•

THANKS, this worked. Thank your very much for the close reading and the tip!

1
mrrichardcranium•

Glad to help!

1