Mattermost mobile too many http redirect (RESOLVED)

1. The problem I’m having: Mattermost Mobile infinite redirect

Mattermost mobile has a bug where you cannot log in because of an infinite redirect. Many people have solved it by using Nginx as a reverse proxy with this configuration.

 if ($request_method = HEAD) {
        return 200;
    }

How can I reproduce it on the caddyfile?

Thanks for the support.

2. Error messages and/or full log output: Too many Follow-up requests:21

{"level":"info","ts":1732097992.3141901,"logger":"http.log.access.log161","msg":"handled request","request":{"remote_ip":"151.82.207.162","remote_port":"63037","client_ip":"151.82.207.162","proto":"HTTP/2.0","method":"HEAD","host":"mmost.gnet.it","uri":"/","headers":{"Accept-Encoding":["gzip"],"User-Agent":["okhttp/4.12.0"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mmost.gnet.it"}},"bytes_read":0,"user_id":"","duration":0.000866924,"size":0,"status":302,"resp_headers":{"Date":["Wed, 20 Nov 2024 10:19:52 GMT"],"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Type":["text/html; charset=utf-8"],"Location":["/gn/mattermost"]}}
{"level":"info","ts":1732097992.4659443,"logger":"http.log.access.log161","msg":"handled request","request":{"remote_ip":"151.82.207.162","remote_port":"63037","client_ip":"151.82.207.162","proto":"HTTP/2.0","method":"HEAD","host":"mmost.gnet.it","uri":"/gn/mattermost","headers":{"User-Agent":["okhttp/4.12.0"],"Accept-Encoding":["gzip"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mmost.gnet.it"}},"bytes_read":0,"user_id":"","duration":0.000895313,"size":0,"status":302,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Type":["text/html; charset=utf-8"],"Location":["/gn/mattermost/"],"Date":["Wed, 20 Nov 2024 10:19:52 GMT"]}}
{"level":"info","ts":1732097992.5331633,"logger":"http.log.access.log161","msg":"handled request","request":{"remote_ip":"151.82.207.162","remote_port":"63037","client_ip":"151.82.207.162","proto":"HTTP/2.0","method":"HEAD","host":"mmost.gnet.it","uri":"/gn/mattermost/","headers":{"Accept-Encoding":["gzip"],"User-Agent":["okhttp/4.12.0"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mmost.gnet.it"}},"bytes_read":0,"user_id":"","duration":0.000924632,"size":0,"status":302,"resp_headers":{"Date":["Wed, 20 Nov 2024 10:19:52 GMT"],"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Type":["text/html; charset=utf-8"],"Location":["/gn/mattermost/gn/mattermost"]}}
{"level":"info","ts":1732097992.6056454,"logger":"http.log.access.log161","msg":"handled request","request":{"remote_ip":"151.82.207.162","remote_port":"63037","client_ip":"151.82.207.162","proto":"HTTP/2.0","method":"HEAD","host":"mmost.gnet.it","uri":"/gn/mattermost/gn/mattermost","headers":{"Accept-Encoding":["gzip"],"User-Agent":["okhttp/4.12.0"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mmost.gnet.it"}},"bytes_read":0,"user_id":"","duration":0.00091617,"size":0,"status":302,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Type":["text/html; charset=utf-8"],"Location":["/gn/mattermost/gn/mattermost/gn/mattermost"],"Date":["Wed, 20 Nov 2024 10:19:52 GMT"]}}
{"level":"info","ts":1732097992.6691031,"logger":"http.log.access.log161","msg":"handled request","request":{"remote_ip":"151.82.207.162","remote_port":"63037","client_ip":"151.82.207.162","proto":"HTTP/2.0","method":"HEAD","host":"mmost.gnet.it","uri":"/gn/mattermost/gn/mattermost/gn/mattermost","headers":{"Accept-Encoding":["gzip"],"User-Agent":["okhttp/4.12.0"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mmost.gnet.it"}},"bytes_read":0,"user_id":"","duration":0.002526794,"size":0,"status":302,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Type":["text/html; charset=utf-8"],"Location":["/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost"],"Date":["Wed, 20 Nov 2024 10:19:52 GMT"]}}
{"level":"info","ts":1732097992.7382922,"logger":"http.log.access.log161","msg":"handled request","request":{"remote_ip":"151.82.207.162","remote_port":"63037","client_ip":"151.82.207.162","proto":"HTTP/2.0","method":"HEAD","host":"mmost.gnet.it","uri":"/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost","headers":{"User-Agent":["okhttp/4.12.0"],"Accept-Encoding":["gzip"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mmost.gnet.it"}},"bytes_read":0,"user_id":"","duration":0.000979785,"size":0,"status":302,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Location":["/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost"],"Date":["Wed, 20 Nov 2024 10:19:52 GMT"],"Content-Type":["text/html; charset=utf-8"]}}
{"level":"info","ts":1732097992.7954817,"logger":"http.log.access.log161","msg":"handled request","request":{"remote_ip":"151.82.207.162","remote_port":"63037","client_ip":"151.82.207.162","proto":"HTTP/2.0","method":"HEAD","host":"mmost.gnet.it","uri":"/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost","headers":{"Accept-Encoding":["gzip"],"User-Agent":["okhttp/4.12.0"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mmost.gnet.it"}},"bytes_read":0,"user_id":"","duration":0.0009587,"size":0,"status":302,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Location":["/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost/gn/mattermost"],"Date":["Wed, 20 Nov 2024 10:19:52 GMT"],"Content-Type":["text/html; charset=utf-8"]}}

3. Caddy version: v2.7.6

4. How I installed and ran Caddy: Caddy Reverse Proxy on Ubuntu Server

a. System environment: Ubuntu 22.04 Server systemd

b. Command:

/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile.

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]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target
~                            

d. My complete Caddy config:

mmost.gnet.it {
        log {
                output file /var/log/caddy/mmost.gnet.it.log
        }
        reverse_proxy mattermost-gn.c.clicker-2017.internal:8065
}

5. Links to relevant resources:

https://mattermost.atlassian.net/browse/MM-58042

Howdy @Davide_Quattrini, welcome to the Caddy community.

That sounds like an annoying little bug! Good to hear at least that the workaround seems pretty simple.

First, you’ll need a request method matcher to catch the HEAD method. Then, you want a respond directive to return a 200 response to the client for things matching that request matcher.

@head method HEAD
respond @head 200

You shouldn’t need any further configuration in your case as respond has a higher priority than reverse_proxy so just having the matcher+respond present in your Caddyfile should intercept all the HEAD requests.

1 Like

Great!! It works

Many Thanks.