Need help with try_files

1. Output of caddy version:


2. How I run Caddy:

a. System environment:

debian 11 with docker

b. Command:

docker stack deploy -c docker-compose.yml app.

c. Service/unit/compose file:

version: "3.6"

  # Web proxy for SSL termination
    image: caddy:latest
    #image: delver/caddy-security
    #restart: unless-stopped
    # HTTP et HTTPS
      - "80:80"
      - "443:443"
      - caddy
      - ./apps/caddy/Caddyfile:/etc/caddy/Caddyfile:ro  #fichier de configuration principal de Caddy
      - ./data/caddy:/data  #indispensable pour stocker les données de certificats
      - ./apps/publichtml:/srv:ro 

d. My complete Caddy config:

    # email to generate a valid SSL certificate

    #HTTP/3 support
    servers {
        protocol {

# snippet de règle de réécriture, permet d'être appelé en import dans chacun des sites php
(rewriterule) {
#Règle de réécriture de l'accueil Ademe
@accueil path_regexp accueil ^/accueil.*
rewrite @accueil /solutions/index.php
#Règle de réécriture des dossiers Ademe
@solfolder path_regexp solfolder .*f([0-9]+).html
rewrite @solfolder /solutions/folder.php?folid={re.solfolder.1}
#Règle de réécriture des stage Ademe
@solstage path_regexp solstage .*s([0-9]+).html
rewrite @solstage /solutions/stage.php?folid=26&stageid={re.solstage.1}
#Règle de réécriture des sessions (formulaire d'inscription) Ademe
@solinscr path_regexp solinscr .*r([0-9]+).html
rewrite @solinscr /solutions/beforeregister.php?sessionid={re.solfolder.1}
#Règle de réécriture recherche de formation (searchstage) Ademe
@searchstage path_regexp searchstage .*recherche-de-formation.html
rewrite @searchstage /solutions/searchstage.php
#Règle de réécriture contactez-nous (contact) Ademe
@contact path_regexp contact .*contactez-nous.html
rewrite @contact /solutions/contact.php
@contact-thankyou path_regexp contact-thankyou .*remerciements-contact.html
rewrite @contact-thankyou /solutions/contact-thankyou.php
#Règle de réécriture plan du site (sitemap) Ademe
@sitemap path_regexp sitemap .*plan-du-site.html
rewrite @sitemap /solutions/sitemap.php

#Règle de réécriture formulaire d'inscription (register & co) Ademe
# Voir l'envoi de variable en get pour rewriting entre beforeregister => register ex :(secteur=2&sessionid=1292&formval=Valider)
# Voir les actions des form pour le rewriting
@forminsc path_regexp forminsc .*formulaire-d-inscription.html
rewrite @forminsc /solutions/beforeregister.php
@register path_regexp register .*participant.html
rewrite @register /solutions/register.php
@register2 path_regexp register2 .*responsable.html
rewrite @register2 /solutions/register2.php
@register3 path_regexp register3 .*societe.html
rewrite @register3 /solutions/register3.php
@register4 path_regexp register4 .*facturation.html
rewrite @register4 /solutions/register4.php
@register5 path_regexp register5 .*message.html
rewrite @register5 /solutions/register5.php
@register6 path_regexp register6 .*synthese.html
rewrite @register6 /solutions/register6.php
@register7 path_regexp register7 .*enregistrement-formulaire-d-inscription.html
rewrite @register7 /solutions/register7.php
@register-thankyou path_regexp register-thankyou .*remerciements.html
rewrite @register-thankyou /solutions/register-thankyou.php

#Règle de réécriture formulaire création d'un compte (account & co)
# Voir l'envoi de variable en get pour rewriting entre beforecreateaccount => createaccount ex : (secteur=2&
# Voir les actions des form pour le rewriting
@beforecreateaccount path_regexp beforecreateaccount .*creation-de-compte.html
rewrite @beforecreateaccount /solutions/beforecreateaccount.php
@createaccount path_regexp createaccount .*creation-compte-vos-informations.html
rewrite @createaccount /solutions/createaccount.php
@createaccount2 path_regexp createaccount .*creation-compte-societe.html
rewrite @createaccount2 /solutions/createaccount2.php
@createaccount3 path_regexp createaccount3 .*creation-compte-message.html
rewrite @createaccount3 /solutions/createaccount3.php
@createaccount4 path_regexp createaccount4 .*creation-compte-synthese.html
rewrite @createaccount4 /solutions/createaccount4.php
@createaccount5 path_regexp createaccount5 .*creation-compte-enregistrement.html
rewrite @createaccount5 /solutions/createaccount5.php
@createaccount-thankyou path_regexp .*creation-compte-remerciement.html
rewrite @createaccount-thankyou /solutions/createaccount-thankyou.php
#Rewrite FAQ
@searchfaq path_regexp searchfaq .*faq.html
rewrite @searchfaq /solutions/searchfaq.php
#Règle de réécriture de la FAQ
@faq path_regexp faq .*a([0-9]+).html
rewrite @faq /solutions/faq.php?faqid={re.faq.1}
# Site PHP {
# On indique quel sera le dossier racine du serveur web
root * /srv
encode gzip zstd
handle_path /simplesaml* {
  uri strip_prefix /simplesaml
  root * /srv/external/simplesamlphp/www
  encode gzip zstd
#try_files /{path} {path}/index.php /notfound.html
import rewriterule
header {
        Strict-Transport-Security max-age=31536000;
        X-Content-Type-Options nosniff;
        X-XSS-Protection "1; mode=block;"
        X-Robots-Tag none;
        X-Frame-Options SAMEORIGIN;
        Referrer-Policy no-referrer;

3. The problem I’m having:

Hi the community,
I try to explain the context:
I have a container php-fpm witch deliver my webapp on the root /srv.
In this container, I have also another app (simpleSAMLphp) located on /srv/external/simplesamlphp/www

I have many rewriterules for my webapp and I have also a try_files directive:
try_files /{path} {path}/index.php /notfound.html

This directive is for errors pages. it redirects to /notfound.html

when this directive is active , simpleSAMLphp is not available with many redirects.
If it is inactive, the simpleSAMLphp is available but i don’t have redirect for webpages errors.

Could you help me please ?


4. Error messages and/or full log output:

Paste logs/commands/output here.

5. What I already tried:

6. Links to relevant resources:

Which version exactly? Run docker compose exec caddy caddy version to find out.

The version matters, because it affects the answers we can give.

Either way, using latest is a bad idea. You should pin to a specific version of the software you use.

Hello Francis,

v2.6.0 h1:lHDynvM+sTOi9Aq4Y15b4FtkqzPB36WbUrZvVdwzTCA=


Me again,

I just see this :

I do same thing. One handle_path for simpleSAMLphp and handle for my website.
It works.


1 Like

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