Dolibarr and nginx configuration - api REST doesn't work

1.3k Views Asked by At

Dolibarr version : 10.0.3 - api documentation : https://wiki.dolibarr.org/index.php/Module_Web_Services_API_REST_(developer). I can't find anything about the configuration of nginx in the dolibarr documentation. But it seems to be a nginx configuration problem.

The part of the nginx configuration with locations :

location / {
        try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
}

I tested everything I found without success as add:

#test 1
rewrite ^/api/index.php/explorer(.*)$ /api/index.php last;

#test 2
location /api {
    if ( !-e $request_filename) {
         rewrite ^.* /api/index.php last;
    }
}

#test 3
location ~ ^/api/(?!(index\.php))(.*) {
    try_files $uri /api/index.php/$2?$query_string;
}

With the first 2 solutions the API api/index.php/explore responds but I don't have access to the login:

enter image description here

I should have this:

enter image description here

1

There are 1 best solutions below

0
On

This work well : https://wiki.dolibarr.org/index.php/Module_Web_Services_API_REST_(developer)#Nginx_setup

server {
    listen      80;
    server_name     dolibarr.localhost; # adjust to your domain

    root    /usr/share/webapps/dolibarr/htdocs; # adjust to your path 
    index   index.php;

    # from https://github.com/Dolibarr/dolibarr/issues/6163#issuecomment-391265538
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        # Mitigate https://httpoxy.org/ vulnerabilities
        fastcgi_param HTTP_PROXY "";

        root           /usr/share/webapps/dolibarr/htdocs;
        fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        # Dolibarr Rest API path support
        fastcgi_param  PATH_INFO       $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_script_name;
    }
 }