Redirect loop detected

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g. https://crt.sh/?q=example.com), so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is: https://band.snu.ac.kr

I ran this command: certbot certonly --webroot -w /opt/mrsnu.github.io/ -d band.snu.ac.kr -v

It produced this output:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Certificate is due for renewal, auto-renewing...
Renewing an existing certificate for band.snu.ac.kr
Performing the following challenges:
http-01 challenge for band.snu.ac.kr
Using the webroot path /opt/mrsnu.github.io for all unmatched domains.
Waiting for verification...
Challenge failed for domain band.snu.ac.kr
http-01 challenge for band.snu.ac.kr

Certbot failed to authenticate some domains (authenticator: webroot). The Certificate Authority reported these problems:
  Domain: band.snu.ac.kr
  Type:   connection
  Detail: 147.46.15.17: Fetching http://band.snu.ac.kr/.well-known/acme-challenge/NJF3mw7CMde2oYCTus_ki57ux9sbXmjwQvmOjlUcJfE: Redirect loop detected

Hint: The Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet.

Cleaning up challenges
Some challenges have failed.
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

My web server is (include version): nginx/1.18.0 (Ubuntu)

The operating system my web server runs on is (include version): Ubuntu 20.04.6 LTS

My hosting provider, if applicable, is:

I can login to a root shell on my machine (yes or no, or I don't know): Yes

I'm using a control panel to manage my site (no, or provide the name and version of the control panel): No

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot): certbot 2.10.0

Additionally, I get

Hello @juimdpp, welcome to the Let's Encrypt community. :slightly_smiling_face:

Please show the output of sudo nginx -T ; that is a Capital T

Presently I see this https://letsdebug.net/band.snu.ac.kr/1960368

1 Like

That's weird... When I tried yesterday, it ran without any problem. Here's the output for sudo nginx -T:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        #ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        #ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

# configuration file /etc/nginx/modules-enabled/50-mod-http-image-filter.conf:
load_module modules/ngx_http_image_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-xslt-filter.conf:
load_module modules/ngx_http_xslt_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-mail.conf:
load_module modules/ngx_mail_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-stream.conf:
load_module modules/ngx_stream_module.so;

# configuration file /etc/nginx/mime.types:

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

# configuration file /etc/nginx/sites-enabled/band_website_https.conf:
server {
    listen 443 ssl http2;
    listen [::]:443 ssl;
    server_name band.snu.ac.kr www.band.snu.ac.kr;

    ssl_certificate /etc/letsencrypt/live/band.snu.ac.kr/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/band.snu.ac.kr/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384";

    # Specify the root directory and index files
    root /opt/mrsnu.github.io;
    index index.html index.htm;


    #if (!-f "${request_filename}index.html") {
    #    rewrite ^/(.*)/$ /$1 permanent;
    #}

    #if ($request_uri ~* "/index.html") {
    #    rewrite (?i)^(.*)index\.html$ $1 permanent;
    #}

    #if ($request_uri ~* ".html") {
    #    rewrite (?i)^(.*)/(.*)\.html $1/$2 permanent;
    #}

    location / {
        try_files $uri.html $uri $uri/ /index.html;
    }

    location ~ /.well-known/acme-challenge/ {
        allow all;
        root /opt/mrsnu.github.io;
        try_files $uri =404;
        break;
    }

    # Redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}



server {
    listen 80;
    listen [::]:80;
    server_name band.snu.ac.kr www.band.snu.ac.kr;

 #   location / {
#       return 301 https://$server_name$request_uri;
    #}

    location  /.well-known/acme-challenge/ {
        allow all;
        root /opt/mrsnu.github.io;
        try_files $uri =404;
        break;
    }

    location / {
        return 301 https://$server_name$request_uri;
    }

}

# configuration file /etc/nginx/sites-enabled/hcs_nginx.conf:
# /etc/nginx/site-avaliable/hcs_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/firewall/fwmanager/hcs.sock; # for a file socket
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8000 ssl;
    root        /home/firewall/fwmanager;
    # the domain name it will serve for
    server_name hcs.snu.ac.kr; # substitute your machine's IP address or FQDN
    charset     utf-8;

    error_page 497  https://$host:8000$request_uri;

    ssl_certificate     /etc/letsencrypt/live/hcs.snu.ac.kr/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/hcs.snu.ac.kr/privkey.pem;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /home/firewall/fwmanager/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass       django; # for a file socket
        include          /home/firewall/fwmanager/uwsgi_params; # the uwsgi_params file you installed
    }
}

# configuration file /home/firewall/fwmanager/uwsgi_params:
uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;
# configuration file /etc/nginx/sites-enabled/hcs_website_https.conf:
server {
    listen 443 ssl http2;
    #listen [::]:443 ssl http2;
    server_name hcs.snu.ac.kr www.hcs.snu.ac.kr;


    ssl_certificate /etc/letsencrypt/live/hcs.snu.ac.kr/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/hcs.snu.ac.kr/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384";

    # Specify the root directory and index files
    root /opt/labsite/_site;
    index index.html index.htm;


#    if (!-f "${request_filename}index.html") {
#        rewrite ^/(.*)/$ /$1 permanent;
#    }

#    if ($request_uri ~* "/index.html") {
#        rewrite (?i)^(.*)index\.html$ $1 permanent;
#    }

#    if ($request_uri ~* ".html") {
#        rewrite (?i)^(.*)/(.*)\.html $1/$2 permanent;
#    }

    location ^~ /.well-known/acme-challenge/ {
        allow all;
        root /opt/labsite/_site;
        try_files $uri =404;
        break;
    }

    location / {
        try_files $uri.html $uri $uri/ /index.html;
    }

    # Redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

server {
    listen 80;
#    listen [::]:80;
    server_name hcs.snu.ac.kr www.hcs.snu.ac.kr;

   location / {
        return 301 https://$server_name$request_uri;
    }

   location ^~ /.well-known/acme-challenge/ {
        allow all;
        root /opt/labsite/_site;
        try_files $uri =404;
        break;
   }
}

@juimdpp,

Demonstrating the redirect loop.

You can see it with Let's Debug here: https://letsdebug.net/band.snu.ac.kr/1961042?debug=y

IssueFromLetsEncrypt
ERROR
A test authorization for band.snu.ac.kr to the Let's Encrypt staging service has revealed issues that may prevent any certificate for this domain being issued.
147.46.15.17: Fetching http://band.snu.ac.kr/.well-known/acme-challenge/ZWJC1MyXHAs24c5OKWx0ASSVxWR0GYvX9bwFzlxIPe8: Redirect loop detected
HTTPCheck
DEBUG
Requests made to the domain
Request to: band.snu.ac.kr/147.46.15.17, Result: [Address=147.46.15.17,Address Type=IPv4,Server=nginx/1.18.0 (Ubuntu),HTTP Status=302,Number of Redirects=2,Final HTTP Status=404], Issue:
Trace:
@0ms: Making a request to http://band.snu.ac.kr/.well-known/acme-challenge/letsdebug-test (using initial IP 147.46.15.17)
@0ms: Dialing 147.46.15.17
@661ms: Server response: HTTP 302 Found
@661ms: Received redirect to http://band.snu.ac.kr/00867224609/.well-known/acme-challenge/letsdebug-test
@661ms: Dialing 147.46.15.17
@1332ms: Server response: HTTP 302 Found
@1332ms: Received redirect to http://band.snu.ac.kr/.well-known/acme-challenge/letsdebug-test
@1332ms: Dialing 147.46.15.17
@2030ms: Server response: HTTP 404 Not Found

And here with curl

>curl -i http://band.snu.ac.kr/.well-known/acme-challenge/sometestfile
HTTP/1.0 302 Found
Location: http://band.snu.ac.kr/002770519539/.well-known/acme-challenge/sometestfile
Connection: close
Content-Type: text/html; charset=iso-8859-1

The above redirects http://band.snu.ac.kr/.well-known/acme-challenge/sometestfile
to http://band.snu.ac.kr/002770519539/.well-known/acme-challenge/sometestfile

>curl -i http://band.snu.ac.kr/002770519539/.well-known/acme-challenge/sometestfile
HTTP/1.0 302 Found
Location: http://band.snu.ac.kr/.well-known/acme-challenge/sometestfile
Connection: close
Content-Type: text/html; charset=iso-8859-1

The above redirects http://band.snu.ac.kr/002770519539/.well-known/acme-challenge/sometestfile
to http://band.snu.ac.kr/.well-known/acme-challenge/sometestfile

And thus the redirect loop.

2 Likes

Thank you so much for checking! It's really weird, because when I checked myself (with curl), I found that it works...
I get the following:

$ curl -i http://band.snu.ac.kr/.well-known/acme-challenge/sometestfile
HTTP/1.1 404 Not Found
Server: nginx/1.18.0 (Ubuntu)
Date: Fri, 17 May 2024 03:06:28 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>
(base)
hscor@DESKTOP-QGVRU2G MINGW64 ~
$ curl -i http://band.snu.ac.kr/.well-known/acme-challenge/file.txt
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Fri, 17 May 2024 06:47:34 GMT
Content-Type: text/plain
Content-Length: 7
Last-Modified: Thu, 16 May 2024 10:11:30 GMT
Connection: keep-alive
ETag: "6645dbd2-7"
Accept-Ranges: bytes

Hello!
(base)

Also, would you recommend me some steps that I could follow to make this work? It would be really helpful!

1 Like

What firewalls or other network devices do you have between your nginx server and the public internet? Because it looks to me like some security device or software is doing an initial set of redirects. Possibly for any new IP address making a request.

See below series from my own test server

# Notice redirect with series of numbers after the domain name
curl -i http://band.snu.ac.kr/.well-known/acme-challenge/Test404
HTTP/1.0 302 Found
Location: http://band.snu.ac.kr/001246640706/.well-known/acme-challenge/Test404
Connection: close
Content-Type: text/html; charset=iso-8859-1

# Following that redirect gets redirected back to original
# This looks like a redirect loop except see next curl
curl -i http://band.snu.ac.kr/001246640706/.well-known/acme-challenge/Test404
HTTP/1.0 302 Found
Location: http://band.snu.ac.kr/.well-known/acme-challenge/Test404
Connection: close
Content-Type: text/html; charset=iso-8859-1

# Following that redirect (for the original URL) now does NOT get redirected 
# Instead gets the expected 404 Not Found 
# Also note the "Server: nginx" header which is not in above requests
curl -i http://band.snu.ac.kr/.well-known/acme-challenge/Test404
HTTP/1.1 404 Not Found
Server: nginx/1.18.0 (Ubuntu)
Date: Fri, 17 May 2024 13:39:34 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive

Something is probably associating the 12-digit number in your initial redirect with the IP address of the requester. Such that the subsequent requests from same IP don't get the extra redirects.

This is not a loop since it does finally resolve. But, it looks like one and Let's Encrypt protects itself by rejecting your cert request when it gets redirected back to the original URL.

4 Likes

What version of curl did you use?

My linux one didn't see it either, to find the detail I was using

>curl --version
curl 8.7.1 (amd64-portbld-freebsd13.2) libcurl/8.7.1 OpenSSL/1.1.1t zlib/1.2.13 libpsl/0.21.5 libssh2/1.11.0 nghttp2/1.61.0
Release-Date: 2024-03-27
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets
2 Likes

Probably because whatever device or software is doing the redirect with the long number already recognized your IP address. See my previous post.

The Let's Encrypt servers often use different IP addresses. If I am right about this security device / software then you will often have cert request failures. If you repeat the cert request immediately after failure it might work if you get lucky and the LE servers still have their prior IP. This is not a good thing to rely on. You should find out what is doing the faulty redirect and correct that.

Or, consider using the DNS Challenge instead. That uses DNS records rather than HTTP requests to validate your domain.

4 Likes

I'm using curl 7.68.0!

1 Like

I think you're right. Last time I wanted to renew the certificate, it kept not working then suddenly did after multiple attempts, even though I used the same command. And sometimes when I would try the same command but as a dry run (--dry-run), it would work...
Thanks for the tip! I'll check if there is any other device that does some redirects!

3 Likes

Try it on FreeBSD.

Also try from an external network; one that comes from outside your local area network.

2 Likes

Yeah! I did try it at home (outside the local area), and it shows the same thing as your result.
I initially thought it was a firewall problem, since we originally blocked every incoming IP, but I checked with ufw and saw that we're currently allowing incoming access for port 80 and 443.

2 Likes