我今天在运行 Nginx 的网络服务器上安装了 dokuwiki 和 farmer 插件。不幸的是,所有文档都是针对 Apache 的,而我不太擅长自己搞定这些东西。搜索了网络,我只找到了一个问题,询问在 FQDN 后使用 URL 重写。我想要设置 farm 以在 sub.domain.com 下构建每个子域,即 wiki.sub.domain.com。我觉得这应该没有想象的那么难,但是……就目前情况而言,该插件确实正确地构建了子域地址,但它没有正确定向。我在 sites-available 中有一个服务器块,可以进行正常重定向,提供对 farmer 的访问。因此,问题是,https://www.dokuwiki.org/farms和https://www.dokuwiki.org/plugin:farmer,如何正确构建以 *.sub.domain.com 作为插件构建的 FQDN 的服务器块?我需要输入什么来进行重定向或重写?我有一个带有 *.sub 的 DNS A 条目,我很确定它应该可以正确指向,但我知道如果不重写它就无法工作。
server {
#listen 80;
#listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /path/to.crt;
ssl_certificate_key /path/to.key;
ssl_ciphers HIGH:!aNULL:!MD5;
root /path/to/root/html;
server_name sub.domain.com;
index doku.php;
client_max_body_size 1024M;
client_body_timeout 60;
#Support for X-Accel-Redirect
location ~ ^/data/ { internal ; }
location ~ ^/lib.*\.(js|css|gif|png|ico|jpg|jpeg)$ {
expires 365d;
}
location / { try_files $uri $uri/ @dokuwiki; }
location @dokuwiki {
# rewrites "doku.php/" out of the URLs if you set the userwrite setting to .htaccess in dokuwiki config page
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
rewrite ^/(.*) /doku.php?id=$1&$args last;
}
location ~ \.php$ {
try_files $uri $uri/ /doku.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.2-fpm.sock;
}
location ~ /(conf|bin|inc)/ { deny all; }
location ~ /install.php { deny all; }
location ~ /data/ { internal; }
}
有人有什么想法吗?我现在不知道从哪里开始。
答案1
您需要了解 DokuWiki 如何处理动物。
为了创建animal
at animal.sub.domain.com
,
Base Domain for subdomain Animals
您需要在farming/configuration
as 中定义设置sub.domain.com
。
接下来,添加一个新动物
定义Animal Name / Domain
为animal1
现在,Dokuwikianimal1
指向animal1.sub.domain.com
我在 nginx 服务器上测试了这一点,它正确指向域。
此外,如果您使用 SSL,则出于安全目的,您应该将您的 http 服务器重定向到 https。
server {
listen 80;
server_name sub.domain.com;
return 301 https://$host$request_uri;
}
我的sub.domain.com.conf
nginx 设置如下。它还包括用于处理良好 URL 重写的位置块。
server {
listen 80;
server_name sub.domain.com;
return 301 https://$host$request_uri;
autoindex off;
}
# For ssl
server {
ssl on;
ssl_certificate /etc/letsencrypt/live/sub.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sub.domain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
client_max_body_size 20M;
client_body_buffer_size 128k;
default_type application/octet-stream;
listen 443;
server_name sub.domain.com;
root /var/www/html/wiki;
# For ACME challenge
location ~ /.well-known {
allow all;
}
location ~ ^/! {
rewrite ^/!(.*?)/(.*) /$2?$args&animal=$1 last;
rewrite ^/!(.*)$ /?animal=$1 last;
}
location / {
index doku.php;
try_files $uri $uri/ @dokuwiki;
}
location ~ ^/lib.*\.(gif|png|ico|jpg)$ {
expires 30d;
}
location ~ /farm {
index doku.php;
autoindex on;
rewrite ^/farm/?([^/]+)/(.*) /wiki/$2?animal=$1;
rewrite ^/farm/?([^/]+)$ /wiki/?animal=$1;
}
location @dokuwiki {
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
rewrite ^/(.*) /doku.php?id=$1&$args last;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /(data|conf|bin|inc)/ {
deny all;
}
}