nginx 和 dokuwiki 农场

nginx 和 dokuwiki 农场

我正在尝试创建一套 dokuwiki,因此想利用这些农场。

然而我很挣扎,因为说明是针对 apache 的。我可以让一个 dokuwiki 运行得很好,但我无法通过重写产生一个工作农场概念

我一直使用的参考资料是:

https://www.dokuwiki.org/farms

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

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

其中redirect_farm是我一直关注的一个,尤其是step2设置 URL 绑定

这里我们描述简单的URL重写方法,在Apache下使用.htaccess。

将以下内容复制到 /var/www/barn/.htaccess:

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

测试:将浏览器指向http://localhost/barn/foo。您应该看到农民的指数。指向http://localhost/barn/foo/bar。您应该收到 404 错误“未找到请求的 URL /farmer/bar”。这表明 URL 绑定有效。

如果测试失败:

.htaccess 必须在 Apache 配置中启用(AllowOverride All); mod_rewrite 必须包含在内。如果您有重定向循环,则您的 DocumentRoot 需要为 /var/www/ (既不是 /var/www/farmer/ 也不是 /var/www/barn/)。

我有一个稀疏的 localhost.conf 来重新创建它,并包含等效的重写:

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;  
    #}

}

当我去http://localhost我懂了 ”农民“ 和 ”谷仓“。当我浏览时”农民“它列为”农民当我进入“谷仓”时,它被列为“农民”,因此重写的各个方面正在发挥作用。

然而...http://localhost/barn/foo返回 404,这应该列出农民。查看调试日志:

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/"

正则表达式已检测到但重写错误...animal=barn 不应该是这样的。

同样地:

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"

我觉得我已经很接近了,但同样我现在已经到了我不明白 nginx 重写或 dokuwiki 需要什么的地步。有潜水员吗?

答案1

嗯,我已经回答了...

/var/www/localhost/htdocs/farmer是 dokuwiki 的基础

/var/www/localhost/htdocs/barn是一个包含我的农场的目录

/var/www/localhost/htdocs/barn/cow是第一个动物

/var/www/localhost/htdocs/barn/duck是第二个动物

farmer/inc/preload.php 按照提示进行配置:

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

cow/conf/local.protected.php 同等配置

$conf['basedir'] = '/谷仓/牛/';

duck/conf/local.protected.php 同等配置

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

现在 nginx localhost.conf 配置如下:

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;  
    }

}

我可以导航到http://localhost/农夫对于基地,http://localhost/cow(重定向到http://localhost/barn/cow/doku.php,内部重写为http://localhost/farmer/?animal=cow)对于第一只动物,第二只动物也是如此。

我不喜欢 nginx 链式加载的各个方面,但它确实有效(tm)

相关内容