Redirect loop after reverse proxying #5247

Closed
opened 2025-11-02 06:19:05 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @timelf123 on GitHub (Apr 16, 2020).

  • Gitea version (or commit ref): master
  • Git version: latest
  • Operating system: Ubuntu 18.04
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

I get redirect loops and the ROOT_URL does not seem to fix it, nor does adding a trailing slash to the proxy config. I get requests from the browser like this: https://git.site.com/git.site.com/img/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/install

Compose:

    gitea:
        image: gitea/gitea:latest
        container_name: gitea
        labels:
            - "com.dockstarter.appinfo.description: Git repo hosting"
            - "com.dockstarter.appinfo.nicename: Gitea"
        environment:
            - "APP_NAME=Gitea"
            - "ROOT_URL=https://git.site.com/"
            - DOMAIN=git.site.com
            - RUN_MODE=prod
            - SSH_PORT=2222
            - SSH_LISTEN_PORT=2222
            - SSH_DOMAIN=git.site.com
            - USER_GID=1000
            - USER_UID=1000
        restart: always
        volumes:
            - ${DOCKERSHAREDDIR}/gitea:/data
            - /etc/timezone:/etc/timezone:ro
            - /etc/localtime:/etc/localtime:ro
        ports:
            - "2222:2222"
        restart: unless-stopped

Nginx conf:

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name git.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
        include /config/nginx/proxy.conf;
        resolver 127.0.0.11 valid=30s;
        set $upstream_app gitea;
        set $upstream_port 3000;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port/;
    }
}
Originally created by @timelf123 on GitHub (Apr 16, 2020). - Gitea version (or commit ref): master - Git version: latest - Operating system: Ubuntu 18.04 - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description I get redirect loops and the ROOT_URL does not seem to fix it, nor does adding a trailing slash to the proxy config. I get requests from the browser like this: `https://git.site.com/git.site.com/img/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/git.site.com/install` Compose: ``` gitea: image: gitea/gitea:latest container_name: gitea labels: - "com.dockstarter.appinfo.description: Git repo hosting" - "com.dockstarter.appinfo.nicename: Gitea" environment: - "APP_NAME=Gitea" - "ROOT_URL=https://git.site.com/" - DOMAIN=git.site.com - RUN_MODE=prod - SSH_PORT=2222 - SSH_LISTEN_PORT=2222 - SSH_DOMAIN=git.site.com - USER_GID=1000 - USER_UID=1000 restart: always volumes: - ${DOCKERSHAREDDIR}/gitea:/data - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro ports: - "2222:2222" restart: unless-stopped ``` Nginx conf: ``` server { listen 443 ssl; listen [::]:443 ssl; server_name git.*; include /config/nginx/ssl.conf; client_max_body_size 0; location / { include /config/nginx/proxy.conf; resolver 127.0.0.11 valid=30s; set $upstream_app gitea; set $upstream_port 3000; set $upstream_proto http; proxy_pass $upstream_proto://$upstream_app:$upstream_port/; } } ```
Author
Owner

@timelf123 commented on GitHub (Apr 20, 2020):

Was due to incorrect settings previously being written to app.ini

@timelf123 commented on GitHub (Apr 20, 2020): Was due to incorrect settings previously being written to app.ini
Author
Owner

@Adrien-Luxey commented on GitHub (May 7, 2020):

Eyh! I have the same problem while deploying with Docker. Can you elaborate on your error, please? What strikes me is that my app.ini was generated by docker, so it must be a bad docker-compose environment variable that caused the issue. We need to know which it is.

@Adrien-Luxey commented on GitHub (May 7, 2020): Eyh! I have the same problem while deploying with Docker. Can you elaborate on your error, please? What strikes me is that my app.ini was generated by docker, so it must be a bad docker-compose environment variable that caused the issue. We need to know which it is.
Author
Owner

@Adrien-Luxey commented on GitHub (May 7, 2020):

Ok, the problem is ROOT_URL: you get the redirect loop when you wrongly set this environment parameter. I put my TLD: mygitea.tld, although the parameter is used notably for subdirectory installs, e.g. ROOT_URL = https://mysite.tld/git/.

Here's a log trace:

site_1  | [Macaron] 2020-05-07 08:46:49: Started GET / for 92.135.212.67
site_1  | [Macaron] 2020-05-07 08:46:49: Completed GET / 200 OK in 490.058656ms
site_1  | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/assets/octicons/octicons.min.css for 92.135.212.67
site_1  | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/vendor/assets/octicons/octicons.min.css 302 Found in 382.487µs
site_1  | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/css/index.css?v=2150802f140babb659fb7f59b121e3e9 for 92.135.212.67
site_1  | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/css/index.css?v=2150802f140babb659fb7f59b121e3e9 302 Found in 311.623µs
site_1  | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/plugins/jquery-migrate/jquery-migrate.min.js?v=3.0.1 for 92.135.212.67
site_1  | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/vendor/plugins/jquery-migrate/jquery-migrate.min.js?v=3.0.1 302 Found in 323.557µs
site_1  | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/plugins/fomantic/semantic.min.css?v=2150802f140babb659fb7f59b121e3e9 for 92.135.212.67
site_1  | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/vendor/plugins/fomantic/semantic.min.css?v=2150802f140babb659fb7f59b121e3e9 302 Found in 328.687µs
site_1  | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js for 92.135.212.67
site_1  | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js 302 Found in 226.789µs
site_1  | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/plugins/promise-polyfill/polyfill.min.js for 92.135.212.67

What is misleading is that the Installation with Docker page makes me feel like I should set this parameter:

ROOT_URL: ””: Overwrite the automatically generated public URL. This is useful if the internal and the external URL don’t match (e.g. in Docker).

@Adrien-Luxey commented on GitHub (May 7, 2020): Ok, the problem is `ROOT_URL`: you get the redirect loop when you wrongly set this environment parameter. I put my TLD: `mygitea.tld`, although the parameter is used notably for subdirectory installs, e.g. `ROOT_URL = https://mysite.tld/git/`. Here's a log trace: ``` site_1 | [Macaron] 2020-05-07 08:46:49: Started GET / for 92.135.212.67 site_1 | [Macaron] 2020-05-07 08:46:49: Completed GET / 200 OK in 490.058656ms site_1 | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/assets/octicons/octicons.min.css for 92.135.212.67 site_1 | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/vendor/assets/octicons/octicons.min.css 302 Found in 382.487µs site_1 | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/css/index.css?v=2150802f140babb659fb7f59b121e3e9 for 92.135.212.67 site_1 | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/css/index.css?v=2150802f140babb659fb7f59b121e3e9 302 Found in 311.623µs site_1 | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/plugins/jquery-migrate/jquery-migrate.min.js?v=3.0.1 for 92.135.212.67 site_1 | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/vendor/plugins/jquery-migrate/jquery-migrate.min.js?v=3.0.1 302 Found in 323.557µs site_1 | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/plugins/fomantic/semantic.min.css?v=2150802f140babb659fb7f59b121e3e9 for 92.135.212.67 site_1 | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/vendor/plugins/fomantic/semantic.min.css?v=2150802f140babb659fb7f59b121e3e9 302 Found in 328.687µs site_1 | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js for 92.135.212.67 site_1 | [Macaron] 2020-05-07 08:46:50: Completed GET /mygitea.tld/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js 302 Found in 226.789µs site_1 | [Macaron] 2020-05-07 08:46:50: Started GET /mygitea.tld/vendor/plugins/promise-polyfill/polyfill.min.js for 92.135.212.67 ``` What is misleading is that the [Installation with Docker](https://docs.gitea.io/en-us/install-with-docker/) page makes me feel like I should set this parameter: > ROOT_URL: ””: Overwrite the automatically generated public URL. This is useful if the internal and the external URL don’t match (e.g. in Docker).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#5247