basyura's blog

あしたになったらほんきだす。

Docker - DokuWiki をサブディレクトリ運用

DokuWiki が便利なので Docker で立ててみる。

インストール

コンテナを取得して起動 (nginx 版)

$ docker pull vimagick/dokuwiki
$ docker run -d -p 8000:80 --name dokuwiki

初期設定

サイトの設定

  • http://localhost:8000/doku.php?id=start&do=admin&page=config
  • ✓ を入れる → URL上の名前空間の区切りにスラッシュを使用
  • ✓ を外す
    • DokuWikiの更新とセキュリティに関する情報をチェックしますか?
    • 最初の見出しをページ名とする → 常に使用する
  • .htaccess を使用する

コンテナにログイン

$ docker exec -it dokuwiki sh

ディレクトリ名を変更

$ cd /var/www
$ mv html dokuwiki " ディレクトリが消えないけど放置

/etc/nginx/nginx.conf を編集

  • location ~* .(js ・・・ のところを消さないと画像が出ないのがよく分からない
/etc/nginx # diff nginx.conf.org nginx.conf
--- nginx.conf.org
+++ nginx.conf
@@ -17,7 +17,7 @@
  server_name             _;
  client_max_body_size    4M;
  client_body_buffer_size 128k;
- root                    /var/www/html;
+ root                    /var/www;
  index                   doku.php;
 
  location ~ /(data/|conf/|bin/|inc/) {
@@ -31,19 +31,19 @@
    log_not_found       off;
  }
 
- location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
-   expires  31536000s;            
-   add_header  Pragma "public";      
-   add_header  Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
-   log_not_found  off;                                                                        
- }                                                                                                   



- location / {
+ location /dokuwiki {
    try_files     $uri $uri/ @dokuwiki;
  }
 
   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;
+    rewrite   ^/dokuwiki/_media/(.*) /dokuwiki/lib/exe/fetch.php?media=$1 last;
+    rewrite   ^/dokuwiki/_detail/(.*) /dokuwiki/lib/exe/detail.php?media=$1 last;
+    rewrite   ^/dokuwiki/_export/([^/]+)/(.*) /dokuwiki/doku.php?do=export_$1&id=$2 last;
+    rewrite   ^/dokuwiki/(.*) /doku.php?id=$1&$args last;
   }
      
   location ~ \.php$ {
-    try_files           $uri $uri/ /doku.php;
+    try_files           $uri $uri/ /dokuwiki/doku.php;
     include             fastcgi_params;
     fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;
     fastcgi_param       REDIRECT_STATUS 200;

nginx を再起動

$ nginx -s reload

Apache でリバースプロキシ

—link を指定してコンテナを作成する

docker run -d -p 80:80 --name apache \
                       --link dokuwiki:dokuwiki \
                       jmferrer/apache2-reverse-proxy

コンテナに入って設定を変える

$ docker exec -it apache bash
$ apt-get update
$ apt-get install vim
$ vi /etc/apache2/apache2.conf 

以下を追記

ServerName localhost
ProxyPass /dokuwiki http://dokuwiki/dokuwiki
ProxyPassReverse /dokuwiki http://dokuwiki/dokuwiki

再起動

$ apache2ctrl -k restart

Timezone の変更

dokuwiki/inc/init.php L88

// set timezone (as in pre 5.3.0 days)
// date_default_timezone_set(@date_default_timezone_get());                 
date_default_timezone_set('Asia/Tokyo'); 

Plantuml Plugin

プラグインをインストール

必要なソフトウェアをインストール

  • proxy 内からの場合は設定が必要
# apk update
# apk add fontconfig  // 結果いらなかったと思われ
# apk add ttf-dejavu  // 結果いらなかったと思われ
# apk add openjdk7
# apk add graphviz

日本語 (IPA) フォントを入れる

# wget http://ipafont.ipa.go.jp/old/ipafont/ipag00303.php
# unzip ipag00303.php
# mkdir -p /usr/share/fonts/ipa
# cp ipag00303.php/ipag.ttf /usr/share/fonts/ipa
# fc-cache -fv

plantuml.jar をダウンロードして配置

  • http://plantuml.com/download
    • wget でのとり方がよく分からんのでホストにダウンロードしてから docker cp で配置

サイトの設定

  • Render localy にチェック
  • jar のパスを指定 (dokuwiki が見える位置に置く)

Proxy

パッケージを更新しようとすると proxy 判定で失敗する。

~ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/main: Permission denied
WARNING: Ignoring APKINDEX.c51f8f92.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/community: Permission denied
WARNING: Ignoring APKINDEX.d09172fd.tar.gz: No such file or directory

proxy 設定を変更。かなりハマってここだけで半日ぐらい消費。

export http_proxy=http://{host}:8080
export HTTP_PROXY_AUTH=basic:*:proxyuser:proxypass

まとめ

次はコンテナを作ってみる。