YOURLS - Too many redirects

1. Caddy version (caddy version):

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

a. System environment:

Ubuntu 20.04.1 LTS

b. Command:

sudo systemctl start caddy

c. Service/unit/compose file:

# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

test.zerocz.eu {
    root * /var/www/zerocz.eu/test
    route {
        try_files {path} {path}/index.php yourls-loader.php
        php_fastcgi unix//run/php/php7.4-fpm.sock
    }
    file_server
}

3. The problem I’m having:

Maybe there is alredy solution on this forum but I did not find it.
When I try to access yourls by browser I’ll get TOO MANY REDIRECTS error.

4. Links to relevant resources:

What do you see when you make the request with curl -vL?

Loop of redirects to the same url.

That’s not helpful. I’d need to see the logs.

https://pastebin.com/raw/JVxt55s7

Hmm. I bet yourls is triggering those redirects. It’s probably a misconfiguration of yourls. Make sure it’s properly aware of your domain and that you’re serving it over HTTPS.

Configuration is right.

How can you be so sure? I can’t help if you just give terse answers like that.

Here is my configuration from /user/config.php
<?php
/* This is a sample config file.

  • Edit this file with your own settings and save it as “config.php”
  • IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or
  • Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file.
    */

/*
** MySQL settings - You can get this info from your web host
*/

/** MySQL database username /
define( ‘YOURLS_DB_USER’, '
******’ );

/** MySQL database password /
define( ‘YOURLS_DB_PASS’, '
******’ );

/** The name of the database for YOURLS /
define( ‘YOURLS_DB_NAME’, '
*****’ );

/** MySQL hostname.
** If using a non standard port, specify it like ‘hostname:port’, eg. ‘localhost:9999’ or ‘127.0.0.1:666’ */
define( ‘YOURLS_DB_HOST’, ‘localhost’ );

/** MySQL tables prefix */
define( ‘YOURLS_DB_PREFIX’, ‘yourls_’ );

/*
** Site options
*/

/** YOURLS installation URL – all lowercase, no trailing slash at the end.
** If you define it to “http://sho.rt”, don’t use “http://www.sho.rt” in your browser (and vice-versa) */
define( ‘YOURLS_SITE’, ‘https://test.zerocz.eu’ );

/** Server timezone GMT offset */
define( ‘YOURLS_HOURS_OFFSET’, +1 );

/** YOURLS language
** Change this setting to use a translation file for your language, instead of the default English.
** That translation file (a .mo file) must be installed in the user/language directory.
** See YOURLS in your language · YOURLS/YOURLS Wiki · GitHub for more information */
define( ‘YOURLS_LANG’, ‘’ );

/** Allow multiple short URLs for a same long URL
** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
define( ‘YOURLS_UNIQUE_URLS’, true );

/** Private means the Admin area will be protected with login/pass as defined below.
** Set to false for public usage (eg on a restricted intranet or for test setups)
** Read Private Or Public · YOURLS/YOURLS Wiki · GitHub for more details if you’re unsure */
define( ‘YOURLS_PRIVATE’, true );

/** A random secret hash used to encrypt cookies. You don’t have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/
define( ‘YOURLS_COOKIEKEY’, ‘*************’ );

/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
** YOURLS will auto encrypt plain text passwords in this file
** Read Username Passwords · YOURLS/YOURLS Wiki · GitHub for more information /
$yourls_user_passwords = array(
‘ondra’ => ‘*****************************’ /
Password encrypted by YOURLS */ ,
// ‘username2’ => ‘password2’,
// You can have one or more ‘login’=>‘password’ lines
);

/** Debug mode to output some internal information
** Default is false for live site. Enable when coding or before submitting a new issue */
define( ‘YOURLS_DEBUG’, false );

/*
** URL Shortening settings
*/

/** URL shortening method: 36 or 62 /
define( ‘YOURLS_URL_CONVERT’, 36 );
/

  • 36: generates all lowercase keywords (ie: 13jkm)
  • 62: generates mixed case keywords (ie: 13jKm or 13JKm)
  • Stick to one setting. It’s best not to change after you’ve started creating links.
    */

/**

  • Reserved keywords (so that generated URLs won’t match them)
  • Define here negative, unwanted or potentially misleading keywords.
    */
    $yourls_reserved_URL = array(
    ‘porn’, ‘faggot’, ‘sex’, ‘nigger’, ‘fuck’, ‘cunt’, ‘dick’,
    );

/*
** Personal settings would go after here.
*/

This is the configuration I’m using:

mydomain.com {     
   tls email@gmail.com
        root * /var/www/yourls
        route {
                try_files {path} {path}/index.php yourls-loader.php
                php_fastcgi unix//run/php/php7.4-fpm.sock
        }
        file_server
        encode zstd gzip
        log {
                output file     /var/log/caddy/yourls.log
                format single_field common_log
                level           error
        }
}

I have exactly same configuration. I even tried with nginx. Still to many redirects, so its not a problem caused by caddy. I don’t know what am I doing wrong.

This topic was automatically closed after 30 days. New replies are no longer allowed.