0

I am attempting to create a suite of dokuwiki's and thus want to leverage the farms.

I am however struggling as the instructions are for apache. I can get a single dokuwiki running just fine but I am unable to produce a working farm concept via rewrite

The reference material I have been using is:

https://www.dokuwiki.org/farms

https://www.dokuwiki.org/farms:example01

https://www.dokuwiki.org/tips:redirect_farm

the redirect_farm is the one I have been concentrating on, especially step2 Setup the URL binding

Here we describe the simples URL rewrite method, using .htaccess under Apache.

Copy the following to /var/www/barn/.htaccess:

.htaccess
RewriteEngine On
RewriteRule ^/?([^/]+)/(.*)  /farmer/$2?animal=$1 [QSA]
RewriteRule ^/?([^/]+)$      /farmer/?animal=$1 [QSA]
Options +FollowSymLinks

Test: Point your browser to http://localhost/barn/foo. You should see the index of farmer. Point to http://localhost/barn/foo/bar. You should get a 404 error “The requested URL /farmer/bar was not found”. This shows that the URL binding works.

If the test fails:

.htaccess must be enabled in the in the Apache Configuration (AllowOverride All); mod_rewrite must be Included. If you have a redirection loop, your DocumentRoot needs to be /var/www/ (neither /var/www/farmer/ nor /var/www/barn/).

I have a sparce localhost.conf to recreate this and have included the equivalent rewrite:

server {
    listen 80;
    server_name localhost;
    access_log /var/log/nginx/localhost_access_log main;
    error_log /var/log/nginx/localhost_error_log info;
    rewrite_log on;
    root /var/www/localhost/htdocs;
    #location ~ /(data/|conf/|bin/|inc/|install.php) { deny all; }

    location / {
        autoindex on;
        }

    location /barn/ {
        #try_files $uri $uri/ /wiki/doku.php @wiki; 
        autoindex on;
        #alias /var/www/localhost/htdocs/farmer;
        rewrite ^/?([^/]+)/(.*) /farmer/$2?animal=$1 ;
        rewrite ^/?([^/]+)$ /farmer/?animal=$1 ;
    }


    #location ~ \.php$ {
    #   try_files $uri =404;
    #   include /etc/nginx/fastcgi.conf;
    #   fastcgi_pass 127.0.0.1:9000;  
    #}

}

when I goto http://localhost I see "farmer" and "barn". When I browser "farmer" it lists as "farmer". When I go into "barn" it lists as "farmer" so aspects of the rewrite are working.

However... http://localhost/barn/foo returns 404 and this should list farmer. Looking at the debug logs:

2018/07/07 15:25:41 [notice] 17845#17845: *1 "^/?([^/]+)/(.*)" matches "/barn/", client: 127.0.0.1, server: localhost, request: "GET /barn/ HTTP/1.1", host: "localhost", referrer: "http://localhost/"

2018/07/07 15:25:41 [notice] 17845#17845: *1 rewritten data: "/farmer/", args: "animal=barn", client: 127.0.0.1, server: localhost, request: "GET /barn/ HTTP/1.1", host: "localhost", referrer: "http://localhost/"

regex has detected but the wrong rewrite... the animal=barn shouldn't be such.

likewise:

2018/07/07 15:25:44 [notice] 17845#17845: *1 rewritten data: "/farmer/foo/", args: "animal=barn", client: 127.0.0.1, server: localhost, request: "GET /barn/foo/ HTTP/1.1", host: "localhost"

2018/07/07 15:25:44 [notice] 17845#17845: *1 "^/?([^/]+)$" does not match "/farmer/foo/", client: 127.0.0.1, server: localhost, request: "GET /barn/foo/ HTTP/1.1", host: "localhost"

2018/07/07 15:25:44 [error] 17845#17845: *1 "/var/www/localhost/htdocs/farmer/foo/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /barn/foo/ HTTP/1.1", host: "localhost"

I feel I am close but equally I now got to the point I don't understand nginx rewrite or what is needed for dokuwiki. any adive?

2
  • This looks fine to me. the animal=barn shouldn't be such. Why not? According to the dokuwiki documentation, the first part of the URL is the animal. Therefore, in /barn/foo, the animal is barn.
    – Nick ODell
    Jul 7, 2018 at 16:53
  • What I am expecting is: localhost/barn/cow/doku.php --> localhost/farmer/doku.php?animal=cow
    – Naib
    Jul 7, 2018 at 22:08

1 Answer 1

0

Well I have sort of answered it...

/var/www/localhost/htdocs/farmer is the base dokuwiki

/var/www/localhost/htdocs/barn is a directory holding my farm

/var/www/localhost/htdocs/barn/cow is the 1st animal

/var/www/localhost/htdocs/barn/duck is the 2nd animal

farmer/inc/preload.php is configured as per the tips:

if(!defined('DOKU_FARMDIR')) define('DOKU_FARMDIR', '/var/www/localhost/htdocs/barn');

cow/conf/local.protected.php is equally configured

$conf['basedir'] = '/barn/cow/';

duck/conf/local.protected.php is equally configured

$conf['basedir'] = '/barn/duck/';

now the nginx localhost.conf is configured such:

server {
    listen 80;
    server_name localhost;
    access_log /var/log/nginx/localhost_access_log main;
    error_log /var/log/nginx/localhost_error_log info;
    rewrite_log on;
    root /var/www/localhost/htdocs;

    location ~ /(data/|conf/|bin/|inc/|install.php) { deny all; } # post-install lockdown

    location / {
        try_files $uri $uri/ doku.php @farmer;
        autoindex on;
        }
    location /cow {
        return 301 http://$host/barn/cow/doku.php;
        }

    location /duck {
        return 301 http://$host/barn/duck/doku.php;
        }


    location ~ /barn {
        index doku.php;
        autoindex on;
        rewrite ^/barn/?([^/]+)/(.*) /farmer/$2?animal=$1;
        rewrite ^/barn/?([^/]+)$ /farmer/?animal=$1;
        }

    location @farmer {
            rewrite ^/farmer/_media/(.*) /lib/exe/fetch.php?media=$1;
            rewrite ^/farmer/_detail/(.*) /lib/exe/detail.php?media=$1;
            rewrite ^/farmer/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2;
            rewrite ^/farmer/(.*) /doku.php?id=$1&$args;
        }

    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi.conf;
        fastcgi_pass 127.0.0.1:9000;  
    }

}

I can navigate to http://localhost/farmer for base, http://localhost/cow (redirecting to http://localhost/barn/cow/doku.php, internally rewritten as http://localhost/farmer/?animal=cow) for 1st animal and the same for the 2nd.

I don't like aspects of the nginx chainloading but it works(tm)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .