Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse proxy with Traefik on sub-path leads to a HTTP 302 redirection loop #23047

Closed
gelven4sec opened this issue Feb 21, 2023 · 9 comments · Fixed by #23068
Closed

Reverse proxy with Traefik on sub-path leads to a HTTP 302 redirection loop #23047

gelven4sec opened this issue Feb 21, 2023 · 9 comments · Fixed by #23068
Labels

Comments

@gelven4sec
Copy link
Contributor

Description

The title of the issue should be clear, I uploaded a screenshot below.

Here's my Gitea compose :

version: "3"

networks:
  proxy:
    external: true

services:
  gitea:
    image: gitea/gitea:1.18
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - ROOT_URL=https://<MY DOMAIN>/git/
      - OFFLINE_MODE=true
      - DISABLE_SSH=true
      - RUN_MODE=dev
    restart: always
    networks:
      - proxy
    volumes:
      - ./data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 3000:3000
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.gitea.tls=true"
      - "traefik.http.routers.gitea.rule=Host(`<MY DOMAIN>`) && PathPrefix(`/git/`)"
      - "traefik.http.services.gitea.loadbalancer.server.port=3000"

I tried every combination of trailing slashes with ROOT_URL and PathPrefix, couldn't make it work.
If I remove ROOT_URL and access it from https://<MY DOMAIN>:3000 it works fine.

The logs should give you relevant informations.

If we get to find the solution, I would be happy to contribute to documentation about sub-path with traefik like other proxies.

Gitea Version

1.18.4 (Digest: fc835996f659)

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

https://gist.github.com/sven-eliasen/7f9ee471b212417f82f66e9cb0527226

Screenshots

image

Git Version

No response

Operating System

RHEL

How are you running Gitea?

Running with docker, see description for compose.

Database

SQLite

@wxiaoguang
Copy link
Contributor

You need to remove the subpath from Traefik side before passing the request to Gitea.

For example: if a user accesses https://domain/git/ to Traefik, on Gitea side Gitea must seeGET / but not GET /git/

@gelven4sec
Copy link
Contributor Author

You need to remove the subpath from Traefik side before passing the request to Gitea.

So I should do something like a rewrite in nginx ?

@gelven4sec
Copy link
Contributor Author

gelven4sec commented Feb 21, 2023

I appended this at my labels :
- "traefik.http.middlewares.gitea.stripprefix.prefixes=/git"

But seeing my logs, Gitea still receives /git/

@gelven4sec
Copy link
Contributor Author

Even tried this :
- "traefik.http.middlewares.gitea.stripprefixregex.regex=^\/git"

I can see the middleware in Traefik dashboard but it still doesn't seem to work.

@wxiaoguang
Copy link
Contributor

Hmm ... I can only provide these hints but I am not using traefik .... so sorry I have no idea about why traefik stripprefix doesn't work.

@gelven4sec
Copy link
Contributor Author

Hmm ... I can only provide these hints but I am not using traefik .... so sorry I have no idea about why traefik stripprefix doesn't work.

I'll try to get some help by the traefik community.

Thanks for you help ! You sure led my on the right path.

Hope you don't mind keeping this issue open for a while, in case anyone seeing this could help, I'll try to get back here as soon as I get a solution, and update Gitea doc btw.

@techknowlogick
Copy link
Member

Hope you don't mind keeping this issue open for a while, in case anyone seeing this could help.

Of course :) It may get closed in the future, but can always be re-opened.

I'll try to get back here as soon as I get a solution, and update Gitea doc btw.

That would be very appreciated <3 traefik with sub-path is something we don't have documented yet and so any help would be lovely.

@gelven4sec
Copy link
Contributor Author

Okay I finally got this right !

Due to my poor knowledge about Traefik, I though setting up the middleware with the same name as the service would automatically assign it.

Solution :

labels:
      - "traefik.enable=true"
      - "traefik.http.routers.gitea.tls=true"
      - "traefik.http.routers.gitea.rule=Host(`domain`) && PathPrefix(`/git`)"
      - "traefik.http.services.gitea.loadbalancer.server.port=3000"
      - "traefik.http.middlewares.gitea-stripprefix.stripprefix.prefixes=/git"
      - "traefik.http.routers.gitea.middlewares=gitea-stripprefix"

I would be happy to provide a PR to update the documentation, which would close this ticket.

lunny pushed a commit that referenced this issue Feb 23, 2023
Add "Traefik with a sub-path" documentation

closes #23047

Co-authored-by: techknowlogick <[email protected]>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants