🔷Redirection portail publique vers portail privé

🔷Redirection portail publique vers portail privé

Notes

Redirection https://portail.rnmkcy.eu vers https://cwwk.home.arpa si le domaine cwwk.home.arpa est accessible

Paramétrage DNS des navigateurs de la machine de bureau

Firefox

Brave

Librewolf

Dans la page index, avant balise </body>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<script>
(async () => {
  const menu = document.getElementById("homearpa");
  const hote = location.hostname;

  console.log("HĂ´te courant :", hote);

  if (hote === "cwwk.home.arpa") {
    if (menu) menu.style.display = "block";
    return;
  }

  if (hote !== "portail.rnmkcy.eu") {
    console.warn("Hôte inattendu : test ignoré.");
    return;
  }

  if (menu) menu.style.display = "none";

  try {
    const reponse = await fetch("https://cwwk.home.arpa/health", {
      mode: "cors",
      cache: "no-store"
    });

    console.log("Réponse /health :", reponse.status);

    if (reponse.ok) {
      location.replace("https://cwwk.home.arpa/");
    }
  } catch (erreur) {
    console.error("Échec du fetch /health :", erreur);
  }
})();
</script>

La configuration nginx /etc/nginx/conf.d/cwwk.home.arpa.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    allow 192.168.0.0/24;
    allow 100.64.0.0/10;
    allow fd7a:115c:a1e0::/48;
    allow 2a01:e0a:95a:e2f0::/64;
    deny all;
    http2 on;
    server_name cwwk.home.arpa;

    ssl_certificate      /etc/ssl/homearpa/homearpa.crt;
    ssl_certificate_key  /etc/ssl/homearpa/homearpa.key;

    root /sharenfs/rnmkcy/racine/ ;
        location / {
            index portail.php;
        }
  location ~ \.php(?:$|/) {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param HTTPS on;

    fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
    fastcgi_param front_controller_active true;     # Enable pretty urls
    fastcgi_param HTTP_ACCEPT_ENCODING "";          # Disable encoding of nextcloud response to inject ynh scripts
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
  }

location = /health {
    # Pour affichage comme un texte
    default_type text/plain;
    # Autoriser les requĂŞtes en provenance de https://portai.rnmkcy.eu
    add_header Access-Control-Allow-Origin "https://portail.rnmkcy.eu" always;
    #
    add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
    add_header Access-Control-Allow-Headers "Content-Type" always;
    add_header Vary "Origin" always;

    if ($request_method = OPTIONS) {
        return 204;
    }

    return 200 "OK\n";
}
}

Pour éviter les problèmes de cache à chaque modification de la page, demander au navigateur de revalider l’index à chaque visite.
Le Cache-Control va donc dans le bloc server qui sert portail.rnmkcy.eu.

Dans ton cas, le Cache-Control va dans le location PHP, pas dans location /. Pour /, nginx fait une redirection interne vers /portail.php (directive index), puis la réponse est traitée par location ~ \.php. Un add_header placé dans location / ne serait donc jamais appliqué à la page.

1
2
3
4
5
6
7
8
9
    # PHP avec authentification OPTIONNELLE
    location ~ \.php(?:$|/) {
        include snippets/auth.conf;

        add_header Cache-Control "no-cache" always;

        try_files $uri =404;
        # ... le reste inchangé
    }

Puis : sudo nginx -t && sudo systemctl reload nginx.

Le fichier complet /etc/nginx/conf.d/portail.rnmkcy.eu.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name portail.rnmkcy.eu;

    include /etc/nginx/conf.d/ssl-modern.inc;

    root /sharenfs/rnmkcy/racine/;
    index portail.php;

    # Location Authelia
    include snippets/authelia.conf;

    # Intercepter les erreurs au niveau du server
    proxy_intercept_errors on;
    error_page 401 =200 @handle_401;

    # Location interne pour gérer le 401
    location @handle_401 {
        internal;
        return 200;
    }

    # Location principale avec authentification OPTIONNELLE
    location / {
        include snippets/auth.conf;  # Garde ton fichier actuel
        add_header Cache-Control "no-cache" always;
        try_files $uri $uri/ =404;
    }

    # PHP avec authentification OPTIONNELLE
    location ~ \.php(?:$|/) {
        include snippets/auth.conf;  # Garde ton fichier actuel
        
        try_files $uri =404;
        
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS on;
        fastcgi_param modHeadersAvailable true;
        fastcgi_param front_controller_active true;
        fastcgi_param HTTP_ACCEPT_ENCODING "";
        fastcgi_pass unix:/run/php/php8.4-fpm.sock;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }
}

Deux précautions :

  • Si snippets/auth.conf ou snippets/authelia.conf contient dĂ©jĂ  des add_header au niveau du location, ça ne pose pas de problème. Les add_header du mĂŞme niveau s’additionnent. Seuls ceux hĂ©ritĂ©s du niveau server sont Ă©crasĂ©s par ceux d’un location, et ton bloc server n’en a pas.
  • VĂ©rifie le rĂ©sultat avec curl -sI https://portail.rnmkcy.eu/ | grep -i cache-control. Si PHP envoie dĂ©jĂ  son propre Cache-Control (ce que fait session_start()), tu auras deux en-tĂŞtes, sans consĂ©quence fâcheuse. Dans ce cas, tu peux mĂŞme te passer de cet ajout.

Ta page étant générée par PHP, sans Last-Modified ni ETag, les navigateurs ne la mettent normalement pas en cache de façon agressive. Si le problème revient après cet ajout, regarde plutôt du côté d’un service worker ou du cache aller-retour (bfcache) du navigateur mobile, ou d’un cookie Authelia qui modifierait la réponse.