Artificial truth

The more you see, the less you believe.

[archives] [latest] | [homepage] | [atom/rss]

Nginx and php scripts that are using the path as argument
Tue 20 June 2017 — download

I'm running a private dokuwiki instance for various reasons, and recently fell in love with the davcal plugin, that provides a good-looking and usable integration of a graphical calendar, along with synchronisation, either by acting as a caldav server, or via an ics feed.

Unfortunately, its code features things like this in the ics.php file:

$path = explode('/', $_SERVER['REQUEST_URI']);
$icsFile = end($path);

So the path will look like /ics.php/my_ics_file.ics, and since my nginx is configured to only pass (some) .php files to the php interepreter, it won't work.

Fortunately, I have a friend that knows nginx-fu; and here is the trick to get it working:

location ~ ^/lib/plugins/davcal/ics.php/(.*)$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param REDIRECT_STATUS 200;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;