Help with nginx conf

FRANCAIS

Bonjour,

J’essaie d’utiliser le CMS [Translucide] (GitHub - simonvdfr/Translucide: CMS efficient, léger, simple à prendre en main, customisable et écoconçu !) avec une Webapp personnalisée.

Sur mon ordinateur, la conf nginx est aussi simple que la suivante :

server {
        listen 80 ;
        listen [: :]:80 ;

        root /home/thatoo/public_html/mywebsite ;

        # Ajoutez index.php à la liste si vous utilisez PHP
        index index.php index.html index.htm ;

        server_name mywebsite.local ;

        # N'autorisez pas l'accès aux fichiers point (comme .htaccess)
        location ~ /\. {
                deny all ;
        }

        location / {
                # Première tentative pour servir la requête en tant que fichier, puis
                # en tant que répertoire, puis de revenir à l'affichage d'un 404.
                try_files $uri $uri/ /index.php?$args ;
        }

        # Passer les scripts PHP au serveur FastCGI
        location ~ \.php$ {
                include snippets/fastcgi-php.conf ;
                # paramètres par défaut de fastcgi
                include fastcgi_params ;

        # # Avec php-fpm (ou d'autres sockets unix) :
                fastcgi_pass unix:/run/php/php7.3-fpm.sock ;
        }
}

J’ai configuré, sur yunohost, my WebApp sur URL + PATH : https:// mywebsite.com / site
et c’est l’application par défaut pour ce nom de domaine.

La conf nginx créée par My WebApp dans Yunohost est alors la suivante

rewrite ^/site$ /site/ permanent ;
location /site/ {

    # Chemin vers la source
    alias /var/www/my_webapp/www/ ;

    # Index par défaut et fourre-tout
    index index.html index.php ;
    try_files $uri $uri/ /site/index.php?$args ;

    # Eviter les logs inutiles
    location = /site/favicon.ico {
        log_not_found off ;
        access_log off ;
    }
    location = /site/robots.txt {
        autorise tout ;
        log_not_found off ;
        journal d'accès désactivé ;
    }

    # Refuser l'accès aux fichiers et répertoires cachés
    location ~ ^/site/(.+/|)\.(?!well-known\/) {
        refuse tout ;
    }

    # Exécuter et servir les fichiers PHP
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$ ;
        fastcgi_pass unix:/var/run/php/php7.3-fpm-my_webapp.sock ;
        fastcgi_index index.php ;
        include fastcgi_params ;
        fastcgi_param REMOTE_USER $remote_user ;
        fastcgi_param PATH_INFO $fastcgi_path_info ;
        fastcgi_param SCRIPT_FILENAME $request_filename ;
    }

    # Inclure le panneau utilisateur SSOWAT.
    include conf.d/yunohost_panel.conf.inc ;
}

Dans le fichier de configuration du CMS Translucide, j’ai rempli les infos ainsi :

$GLOBALS['scheme'] = "https://" ;

$GLOBALS['domain'] = "mywebsite.com" ;

$GLOBALS['path'] = "/site/" ;

Lorsque je vais sur https://mywebsite.com, il redirige vers https://mywebsite.com/site et affiche joliment la page d’accueil. Cela fonctionne comme prévu.

Cependant, dès que je vais sur une autre page, disons https://mywebsite.com/site/who-are-we, il redirige vers https://myyunohostdomain.com/yunohost/sso et aucune autre page ne peut être affichée.

Si quelqu’un a une idée, je lui en serai très reconnaissant.
Meilleures salutations à tous,
Thatoo

ENGLISH

Hello,

I’m trying to use the CMS Translucide with Custom Webapp.

On my computer, nginx conf is as simple as follow :

server {
        listen 80;
        listen [::]:80;

        root /home/thatoo/public_html/mywebsite;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm;

        server_name mywebsite.local;

        # Don't allow access to dotfiles (such as .htaccess)
        location ~ /\. {
                deny all;
        }

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$args;
        }

        # pass PHP scripts to FastCGI server
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                # default fastcgi settings
                include fastcgi_params;

        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        }
}

I have set, on yunohost, my custom web app on
URL + path : https:// mywebsite.com / site
and it is the default app for this domain name

The nginx conf is then as follow

rewrite ^/site$ /site/ permanent;
location /site/ {

    # Path to source
    alias /var/www/my_webapp/www/;

    # Default indexes and catch-all
    index index.html index.php;
    try_files $uri $uri/ /site/index.php?$args;

    # Prevent useless logs
    location = /site/favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /site/robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # Deny access to hidden files and directories
    location ~ ^/site/(.+/|)\.(?!well-known\/) {
        deny all;
    }

    # Execute and serve PHP files
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm-my_webapp.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param REMOTE_USER $remote_user;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }

    # Include SSOWAT user panel.
    include conf.d/yunohost_panel.conf.inc;
}

The config file of Translucide CMS is filled as follow :

$GLOBALS['scheme'] = "https://";

$GLOBALS['domain'] = "mywebsite.com";

$GLOBALS['path'] = "/site/";

When I go to https://mywebsite.com it redirect to https://mywebsite.com/site and it displays nicely the homepage. It works as expected.

However, as soon as I go on an other page, let’s say https://mywebsite.com/site/who-are-we then it redirects to

https://myyunohostdomain.com/yunohost/sso

so no other pages can be displayed.

If anyone has any idea, I’ll be very much thankfull.
Best regards to all,
Thatoo

FRANCAIS

En m’inspirant du nginx de l’app wordpress de yunohost, je modifie le fichier nginx comme suit :

 rewrite ^/site$ /site/ permanent;
location /site/ {

    # Path to source
    alias /var/www/my_webapp/www/;
    
       index index.php;
       if (!-e $request_filename)
       {
              rewrite ^(.+)$ /site/index.php?q=$1 last;
       }

       # Force usage of https
       if ($scheme = http) {
             rewrite ^ https://$server_name$request_uri? permanent;
       }

       client_max_body_size 30m;
       location ~ [^/]\.php(/|$) {
           fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm-my_webapp.sock;
           fastcgi_index index.php;
           include fastcgi_params;
           fastcgi_param REMOTE_USER $remote_user;
           fastcgi_param PATH_INFO $fastcgi_path_info;
           fastcgi_param SCRIPT_FILENAME $request_filename;
       }

    # Include SSOWAT user panel.
    include conf.d/yunohost_panel.conf.inc;
}

Ca fonctionne déjà beaucoup mieux mais il y a des conflits avec le code de Translucide. [j’arrive au même résultat en m’inspirant du @handler du fichier de conf de PLuxml (pluxml_ynh/nginx.conf at master · YunoHost-Apps/pluxml_ynh · GitHub)]

Par exemple, lorsque je passe en mode admin et que j’enregistre, je me suis rendu compte que le template de la page n’était pas sauvegardé. J’ai enquêté et j’ai trouvé que lucid.edit.js fournissait la valeur de tpl préalablement récupérée par ajax.admin.php à la ligne 99 qui est ainsi

$scandir = array_diff(scandir($_SERVER['DOCUMENT_ROOT'].$GLOBALS['path']."theme/".$GLOBALS['theme'].($GLOBALS['theme']?"/":"")."tpl/"), array('..', '.'));

et ce $GLOBALS[‘path’]. me rajoute un /site dans le chemin de fichier puisque Translucide croit être dans un sous dossier
scandir(/var/www/my_webapp/www/site/theme/nomdutheme/tpl/):
alors qu’il devrait faire
scandir(/var/www/my_webapp/www/theme/nomdutheme/tpl/):

il en va de même pour la gestion des medias (images…)

Je suppose que le problème est que $_SERVER['DOCUMENT_ROOT'] donné par nginx inclut déjà /site/ alors qu’il ne devrait pas. $_SERVER['DOCUMENT_ROOT'] ne devrait être que https://mywebsite.com

ENGLISH

Taking inspiration from the nginx of the yunohost wordpress app, I modify the nginx file as follows:

 rewrite ^/site$ /site/ permanent;
location /site/ {

    # Path to source
    alias /var/www/my_webapp/www/;
    
       index index.php;
       if (!-e $request_filename)
       {
              rewrite ^(.+)$ /site/index.php?q=$1 last;
       }

       # Force usage of https
       if ($scheme = http) {
             rewrite ^ https://$server_name$request_uri? permanent;
       }

       client_max_body_size 30m;
       location ~ [^/]\.php(/|$) {
           fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm-my_webapp.sock;
           fastcgi_index index.php;
           include fastcgi_params;
           fastcgi_param REMOTE_USER $remote_user;
           fastcgi_param PATH_INFO $fastcgi_path_info;
           fastcgi_param SCRIPT_FILENAME $request_filename;
       }

    # Include SSOWAT user panel.
    include conf.d/yunohost_panel.conf.inc;
}

It’s already working much better but there are conflicts with the Translucent code. [I get the same result from the @handler in the PLuxml conf file (pluxml_ynh/nginx.conf at master · YunoHost-Apps/pluxml_ynh · GitHub)]

For example, when I switch to admin mode and save, I realized that the page template was not saved. I investigated and found that lucid.edit.js provided the value of tpl previously retrieved by ajax.admin.php at line 99 which is as follows

$scandir = array_diff(scandir($_SERVER['DOCUMENT_ROOT'].$GLOBALS['path']. "theme/".$GLOBALS['theme'].($GLOBALS['theme']?"/":""). "tpl/"), array('..', '.'));

and this $GLOBALS[‘path’]. adds a /site to the file path since Translucent thinks it is in a sub-folder
scandir(/var/www/my_webapp/www/site/theme/namedutheme/tpl/):
when it should do
scandir(/var/www/my_webapp/www/theme/nomdutheme/tpl/):

it is the same for the management of media (images…)

I guess the problem is that $_SERVER['DOCUMENT_ROOT'] given by nginx includes /site/ already whereas it should not. $_SERVER['DOCUMENT_ROOT'] should only be https://mywebsite.com

FRANCAIS

Pour l’instant mon astuce est d’utiliser le fichier de conf nginx suivant :

location @handler {
  rewrite ^/(.*)$ /site/index.php?^$1 last;
}

location /site/ {

    # Path to source
    alias /var/www/my_webapp/www/;

    # Default indexes and catch-all
    index index.php;
    try_files $uri $uri/ @handler;


    # Execute and serve PHP files
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm-my_webapp.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param REMOTE_USER $remote_user;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }

    include conf.d/yunohost_panel.conf.inc;

location /site/theme/ {
    more_set_headers 'Cache-Control: public';
    expires 12h;
}
location /site/media/ {
    more_set_headers 'Cache-Control: public';
    expires 12h;
}
}

Dans le fichier de configuration du CMS Translucide, j’ai rempli les infos ainsi :

$GLOBALS['scheme'] = "https://" ;

$GLOBALS['domain'] = "mywebsite.com" ;

$GLOBALS['path'] = "/site/" ;

et j’ai tous les dossiers et fichiers en double dans /var/www/my_webapp/www/ et dans /var/www/my_webapp/www/site/

Bien que ce ne soit pas du tout “agréable” à gérer du coup, au moins, ça fonctionne.

ENGLISH

ENGLISH

For now my trick is to use the following nginx conf file:

location @handler {
  rewrite ^/(.*)$ /site/index.php?^$1 last;
}

location /site/ {

    # Path to source
    alias /var/www/my_webapp/www/;

    # Default indexes and catch-all
    index index.php;
    try_files $uri $uri/ @handler;


    # Execute and serve PHP files
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm-my_webapp.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param REMOTE_USER $remote_user;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }

    include conf.d/yunohost_panel.conf.inc;

location /site/theme/ {
    more_set_headers 'Cache-Control: public';
    expires 12h;
}
location /site/media/ {
    more_set_headers 'Cache-Control: public';
    expires 12h;
}
}

In the Translucent CMS configuration file, I filled in the info as follows:

$GLOBALS['scheme'] = "https://" ;

$GLOBALS['domain'] = "mywebsite.com" ;

$GLOBALS['path'] = "/site/" ;

and I have all the duplicate folders and files in /var/www/my_webapp/www/ and in /var/www/my_webapp/www/site/

Although it’s not at all “pleasant” to manage, at least it works.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.