我正试图创建一套dokuwiki,从而想利用农场。
然而,我正在挣扎,因为说明是给apache的。我可以让一个dokuwiki运行得很好,但是我无法通过重写产生一个工作农场的概念。
我一直使用的参考资料是:
https://www.dokuwiki.org/farms
https://www.dokuwiki.org/farms:example01
https://www.dokuwiki.org/tips:redirect_农场
redirect_farm是我一直关注的对象,特别是step2 Setup -- URL绑定
这里我们描述了使用Apache下的.htaccess重写简单URL的方法。将下列文件复制到/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 /农场主/栏”。这表明URL绑定工作正常。如果测试失败:.htaccess必须在(AllowOverride All)中启用;必须包括mod_rewrite。如果您有一个重定向循环,那么您的DocumentRoot需要是/var/www/ (既不是/var/www/farmer/ nor /var/www/barn/)。
我有一个sparce 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需要什么。有进展吗?
发布于 2018-07-07 23:23:27
我已经有点回答了..。
/var/www/localhost/htdocs/farmer是基本dokuwiki
/var/www/localhost/htdocs/barn是保存我的农场的目录
/var/www/localhost/htdocs/畜棚/牛是第一种动物
/var/www/localhost/htdocs/畜棚/鸭是第二种动物
农民/inc/preload.php按照以下提示进行配置:
if(!defined('DOKU_FARMDIR'))定义(‘DOKU_FARMDIR’,'/var/www/localhost/htdocs/barn');
cow/conf/local.tected.php配置相同
$conf =‘/谷仓/牛/’;
鸭/conf/local.tected.php配置相同
$conf =‘/谷仓/鸭/’;
现在,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/farmer的基地,http://localhost/cow (重定向到http://localhost/barn/cow/doku.php,内部重写为http://localhost/farmer/?animal=cow)的第一动物和同样的第二。
我不喜欢nginx链加载的各个方面,但它有效(Tm)。
https://unix.stackexchange.com/questions/454023
复制相似问题