Yunohost + nginx errors in deployment

Hi !

I have developed an API with slim 4 in local environment (apache) following the Odan tutorial : https://odan.github.io/2019/11/05/slim4-tutorial.html

But now i tried to delpoy it in a self hosted server runnig with Yunohost. Yunohost works with Nginx. And i tried to install my API in the custom_webapp application.

So it does not work.

My url app is : mydomain/pvapp/

This url work well : i have an 404 error generated by slim and it’s normal, this route is not set.

But for all the others route nginx don’t works and says to me “Redirection error: unmanaged domain”
My route are in https://mydomain/pvapp/api/v1/theroute

there is my nginx config (stored in : /etc/nginx/conf.d/mydomain.d/my_webapp.conf)

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

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

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

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

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

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

    # Execute and serve PHP files
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.4-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 different of the requierd config of the doc : https://www.slimframework.com/docs/v4/start/web-servers.html#nginx-configuration
But i have tried lots of various adaptations and nothing works.

My API architecture :

My routes.php :

is some knows how to set up my my_webapp.conf nginx config file to make it right ?

Thx a lot !
(and sorry for my bad english)

LaBaude

Hi!

I’m not familiar with Yunohost, but this error message sounds like an Yunohost specific error.

Have your tried: yunohost domain list to get the list of the managed domains?
If you run Slim in a sub-directory: Have you tried this: $app->setBasePath('/pvapp') ?

Thx for your answer !

I have not think about it before, but I have just tried it and it’s worst. Even the mydomain/pvapp/ does not work.

It’s not realy a problem of domain but a problem of url management.

Because in the root url everthing work fine :


i have not set the / root so it’s a normal 404 error. (i have the same in my local environement)

but when I tried an mydomain/pvapp/api/v1/tokens for exemple nginx give to me a 404 error.
And in my yunohost log i can understand that it tried to open the /mydomain/pvapp/api/v1/token file like if the url is a real path :

2020/07/23 19:03:28 [error] 10208#10208: *3161 open() "/var/www/my_webapp/www/public/api/v1/tokens" failed (2: No such file or directory), server: labaudesrv.duckdns.org, request: "POST /pvapp/api/v1/tokens HTTP/1.1", host: "labaudesrv.duckdns.org" 

So I think it is a problem with nginx setup. Probably the url rewriting.