Php content showing without formatting or images

1. Caddy version (caddy version):

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

a. System environment:

Debian Buster, php7.3-fpm.

b. Command:

sudo systemctl start caddy
sudo caddy reload # After edits of the 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]
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:

mala.fr, www.mala.fr {
        tls ma@email.com
        root * /var/www/mala.fr/wordpress
        encode gzip
        php_fastcgi unix//run/php/php7.3-fpm.sock
        # Prevent malicious PHP uploads from running
        @uploads {
                path_regexp path /uploads\/(.*)\.php
        }
        rewrite @uploads /
}

grav.mala.fr, www.grav.mala.fr {
        root * /var/www/mala.fr/grav/base
        encode gzip
        php_fastcgi unix//run/php/php7.3-fpm.sock
}

mattermost.mala.fr, www.mattermost.mala.fr {
        reverse_proxy 127.0.0.1:8065
}

3. The problem I’m having:

I just recently discovered Caddy and I’m quite impressed with the simplicity of Caddyfiles. I was using Nginx before and could never understand 10% of my own configuration files. I decided to try Caddy and got it working for maybe 20 minutes, then suddenly my PHP websites (the main domain and the grav subdomain) started to display as if there was no formatting on the web pages: no images, no correct alignment, no header, etc.

What I do not understand is it was working a few minutes before and I don’t think I changed anything sensible. I was editing my Caddyfile when that happened, but on some other aspects like beautifying my identation or improving comments, and I tried reverted the changes just in case. I really can’t see what has changed between now and when it was working.

Could it be related to a certificate issue blocking the access to some resources called by the Wordpress and Grav sites? Or some cache issue?

The mattermost instance works fine for now.

4. Error messages and/or full log output:

I see no particular error.

5. What I already tried:

I tried commenting out the tls part, triple checked the php-fpm version for php_fastcgi, tried disabling subdomains one by one, to no avail: I could not get back to a state where things worked.

Of note, I then tried from another device, and there again the main page was displayed correctly, until I refreshed it. This makes me wonder if it may involve the cache from a previous visit when Nginx was service those website, as if the website could show correctly by chance thanks to resources already in my cache, but then failing to actually load images and formatting when I refreshed. The weird thing is I hard refreshed maybe 20 times on the first device before everything broke.

6. Links to relevant resources:

Alright, I understood my error. I was missing file_server in both PHP websites. Not sure if it’s me being too tired to realize I deleted it just before things broke, of if the cache actually kept the website working for some time without it, until it broke eventually and I couldn’t directly relate the effect to the cause.

1 Like