Nginxでの設定
Ver3.10よりNginxでの動作を正式サポートしました。
動作環境
- Nginx
- Perl用FCGIモジュール
Debian系の場合は「libfcgi-perl」をインストールしてください。
以下のラッパーモジュールは不要です。adiaryはそのままでFastCGIに対応しています。
- fcgiwrap
- spawn-fcgi
- fastcgi-wrapper.pl
設定方法
Nginx側では以下のように設定します。
server {
listen 80 default_server;
listen [::]:80 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 /;
# Ver3.50より前のバージョンでは以下の設定も必要
fastcgi_param ModRewrite 1;
}
}
- 「<Your-Server-Name>」「/path/to/」の部分はご自分の環境に置き換えてください。
- 「SCRIPT_FILENAME」は不要です。
adiaryを起動させる
この状態で、コンソールからadiary.fcgiを起動すれば利用できます。
./adiary.fcgi 127.0.0.1:9000 30
- 第1引数がListenするポートです。UNIXドメインソケット(ファイル)を指定しても構いません。
- (Ver3.50~)第2引数は生成スレッド数です。デフォルトは10です。
- 実行させた権限で動作しますので、絶対にroot権限で起動してはいけません。
- 常駐させたい場合は最後に「&」を付けてください。
サーバの起動時、自動的に「adiary.fcgi」を起動させるためには、/etc/rc.local にスクリプトを書くなどの何かしらの細工が必要です。
su www-data -c '/path/to/adiary.fcgi 127.0.0.1:9000' &
もしくは、root以外の起動させたいユーザー権限でcrontabを登録するのも良いでしょう。
@reboot /path/to/adiary.fcgi 127.0.0.1:9000 &
UNIX domain socketを使用する場合
TCP接続より少しだけ速くなるUNIX domain socketを使用した設定例です。ソケットのパーミッション問題(502 Bad Gateway)で悩みたくなければ、Ver3.40以降推奨。
location @adiary {
include fastcgi_params;
fastcgi_pass unix:/path/to/adiary.sock;
fastcgi_param Basepath /;
}
./adiary.fcgi adiary.sock
ちょっと特殊な設定例
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/;
}
}