ERR_TOO_MANY_REDIRECTS when using gogs behind nginx


#1

Hello everyone! I installed gogs v0.11.66 on centos 7 using the Postgresql database. However, attempting to visit /git/install gives me an error about hitting too many directs (which I verified is the case with chrome’s developer tools and curl). Looking online at example nginx/gogs configurations, I am unable to see what I am doing wrong. Can someone point out where my mistake is? Thank you!

nginx.conf:

worker_processes 2;

events {
    worker_connections 1024;
}

http {
    access_log /web/nginx/logs/access.log;
    error_log /web/nginx/logs/error.log;

    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout  65;
    gzip on;

    server {
        listen 80 default_server;
        return 302 https://$host$request_uri;
    }

    server {
        listen 443 default_server ssl http2;

        ssl_certificate /web/nginx/ssl/cert.pem;
        ssl_certificate_key /web/nginx/ssl/cert.key;
        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:50m;
        ssl_session_tickets off;

        ssl_protocols TLSv1.2 TLSv1.1;
        ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
        ssl_prefer_server_ciphers on;

        ssl_stapling on;
        ssl_stapling_verify on;

        resolver 1.1.1.1;
        add_header Strict-Transport-Security max-age=15768000;

        location /git {
            proxy_pass https://127.0.0.1:4242;
        }

        location ~ /static/? { # perhaps default content type
            root /web;
        }

        location ~ /users/? { # index file with instructions
            root /web;
            index index.html;
        }

        include /web/nginx/conf.d/*;

        location / {
            root /web/www;
            index index.html;
        }

        #error_page  404              /404.html;
        #error_page   500 502 503 504  /50x.html;
    }
}

custom/conf/app.ini:

APP_NAME = Git Server
RUN_USER = gogs
RUN_MODE = prod

[server]
PROTOCOL = https
DOMAIN = burnedoutbastards.com
ROOT_URL = https://burnedoutbastards.com/git
HTTP_ADDR = 127.0.0.1
HTTP_PORT = 4242
SSH_DOMAIN = %(DOMAIN)s
LANDING_PAGE = explore
CERT_FILE = /web/nginx/ssl/cert.pem
KEY_FILE = /web/nginx/ssl/cert.key

[repository]
SCRIPT_TYPE = bash
MAX_CREATION_LIMIT = 15
PREFERRED_LICENSES = MIT License,Apache License 2.0

[repository.upload]
ENABLED = false

[markdown]
CUSTOM_URL_SCHEMES = magnet,git,http,https,ssh,scp,irc,ircs,ftp
FILE_EXTENSIONS = .md

[mailer]
ENABLED = false

#2

Read very carefully: https://gogs.io/docs/intro/faqs#how-do-i-set-up-a-sub-path-with-nginx%3F


#3

It doesn’t seem a Gogs issue, have you tried another browser? Could you follow https://www.drivereasy.com/knowledge/how-to-fix-err-too-many-redirects-error/ and send the feedback?


#4

@Unknwon When I follow that format, I get a 404 on my user’s page. The gogs log only shows:

2018/09/25 04:34:57 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:34:57 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:34:57 [TRACE] Template: user/settings/profile
2018/09/25 04:34:58 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:34:58 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:34:59 [TRACE] Template: user/settings/repositories
2018/09/25 04:35:05 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:35:05 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:35:05 [TRACE] Template: admin/dashboard
2018/09/25 04:35:07 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:35:07 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:35:07 [TRACE] Template: admin/repo/list
2018/09/25 04:35:11 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:35:11 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:35:11 [TRACE] Repository deleted: nchambers/hello
2018/09/25 04:35:11 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:35:11 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:35:11 [TRACE] Template: admin/repo/list
2018/09/25 04:35:15 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:35:15 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:35:15 [TRACE] Template: user/dashboard/dashboard
2018/09/25 04:35:23 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:35:23 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:35:23 [TRACE] Template: user/profile
2018/09/25 04:35:25 [TRACE] Session ID: 223ad7313afc8e8c
2018/09/25 04:35:25 [TRACE] CSRF Token: F9Iweus9EwkOuBM7zX1NXPHrA5k6MTUzNzg1MDA1NzM0NjU0MzAxNA==
2018/09/25 04:35:25 [TRACE] Template: explore/repos

nginx access.log:

136.62.156.250 - - [25/Sep/2018:04:35:27 +0000] "GET /git/explore/users HTTP/2.0" 404 188 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"

nginx error.log:

2018/09/25 04:35:27 [error] 2839#0: *1557 open() "/web/git/explore/users" failed (2: No such file or directory), client: 136.62.156.250, server: , request: "GET /git/explore/users HTTP/2.0", host: "burnedoutbastards.com"

Here you suggest removing the / as the fix, but this leads to the too many redirects issue.


#5

OK, looks like you double configured HTTPS, you don’t do HTTPS behind HTTPS. So your Gogs should just start as normal HTTP server, let NGINX handle the SSL


#6

I changed it to use http, but it still 404’s.


#7

I suggest you comment out everything but simply just proxy, just to rule out any side-effects could be caused.