Nginxでの設定
Ver3.10よりNginxでの動作を正式サポートしました。
動作環境
- Nginx
- Perl用FCGIモジュール
Debian系の場合は「libfcgi-perl」をインストールしてください。
adiaryは元からFastCGIに対応していますので、以下のラッパーモジュールは不要です。
- fcgiwrap
- spawn-fcgi
- fastcgi-wrapper.pl
設定方法
Nginx側では以下のように設定します。
server { listen 8888 default_server; listen [::]:8888 default_server; server_name <Your-Server-Name>; root /path/to/adiary; location / { try_files $uri @adiary; } location /__cache { deny all; } location /data { deny all; } location ~ \.cgi$ { deny all; } location @adiary { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param Basepath /; fastcgi_param Mod_rewrite 1; } }
- 「<Your-Server-Name>」「/path/to/」の部分はご自分の環境に置き換えてください。
- 「fastcgi_pass」では、UNIXドメインソケット(ファイル)を設定しても構いません。
- 「SCRIPT_FILENAME」は不要です。
adiaryを起動させる
この状態で、コンソールからadiary.fcgiを起動すれば利用できます。
$ ./adiary.fcgi 127.0.0.1:9000 30
- 第1引数がListenするポートです。UNIXドメインソケット(ファイル)を指定しても構いません。
- 第2引数は接続待ちキューの長さです。省略時は「100」になります。
- 実行させた権限で動作しますので、root等で起動しないように注意してください。
- 常駐させたい場合は最後に「&」を付けてください。
サーバの起動時、自動的に「adiary.fcgi」を起動させるためには、/etc/init.d にスクリプトを書くなどの何かしらの細工が必要です。また、スクリプト自体が何かの拍子に落ちるかもしれませんので*1、不安な方は無限ループする起動スクリプト等を書いておくと良いでしょう。
#!/bin/sh # adiary-start.sh : adiary.fcgi start up script while : do /path/to/adiary.fcgi 127.0.0.1:9000 done
このスクリプトを rc.local などから呼び出すとよいと思います。
su www-data -c /path/to/adiary-start.sh &
ちょっと特殊な設定例
Document Rootに置かない場合
もしDocument Root(/path/to)配下の /adiary-path/ に実ファイルを置いた場合は、以下の部分を変更してください。
server { root /path/to; location /adiary-path/ { # 略 } location @adiary { # 略 fastcgi_param Basepath /adiary-path/; } }
aliasのように貼り付ける場合
無関係なDocument Rootに /adiary/ としてaliasのように設置する場合は、以下のようにしてください。
server { listen 80 default_server; listen [::]:80 default_server; server_name theta; root /var/www; location /adiary/ { root /path/to/adiary; if ($uri ~ ^/adiary/(.+)$) { set $x $1; } if (-f $document_root/$x) { rewrite ^/adiary/(.*)$ /$1 break; } error_page 404 = @adiary; } location /adiary/__cache { deny all; } location /adiary/data { deny all; } location ~ \.cgi$ { deny all; } location @adiary { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param Basepath /adiary/; fastcgi_param Mod_rewrite 1; } }