nginx
更新日:2009/6/15
対応ソフトウェア:nginx 0.7.59
SSIを有効にして#execコマンドで外部プログラムを呼び出そうとしても機能せず、[an error occurred while processing the directive]というメッセージが返される。
<!--#exec cmd="<コマンド>"--> <!--#exec cgi="<コマンド>"-->
(関連)
更新日:2009/6/9
対応ソフトウェア:nginx 0.7.59
nginxでSSIを使用するにはnginx.confのに以下の設定を追加する。それぞれの設定はhttp、server、locationのどのディレクティブにも記述可能である。
ssi {on|off}
SSI機能のon/offを指定する。デフォルトはoff。
ssi_silent_errors {on|off}
SSI実行時にエラーが発生するとサーバから[an error occurred while processing the directive]というメッセージが返されるが、このメッセージを抑止するかどうかを指定する。
onなら抑止、offなら出力。デフォルトはoff。
ただしこの設定でメッセージを抑止してもエラー自体は解消されないので注意すること。
メッセージの内容を変更したい場合はHTML内に以下のSSIコマンドを書く。
<!--#config errmsg="SSIでエラーが発生しました"-->
ssi_types
SSI実行時のMIME-type(text/html)に追加のtypeを設定する。
ssi_types text/xml;
ssi_value_length
SSIのコマンドにパラメータを渡す際の最大長。デフォルトは256(バイト)。
この値を越えてパラメータを渡した場合、SSIコマンドは実行されずサーバから[an error occurred while processing the directive]メッセージが返される。
(関連)
更新日:2009/6/7
対応ソフトウェア:nginx 0.7.59
公式サイト
準備
導入OS
Ubuntu 9.04
管理用アカウント作成
% sudo groupadd -r www % sudo useradd -r -g www -s /bin/false -d /nonexistent www
インストール
配布ファイル展開
% tar zxvf nginx-0.7.59.tar.gz % cd nginx-0.7.59
make,インストール
% ./configure --user=www --group=www <オプション>
デフォルトで以下のモジュールが有効になる。
ngx_http_access_module
ngx_http_auth_basic_module
ngx_http_autoindex_module
ngx_http_browser_module
ngx_http_charset_module
ngx_http_empty_gif_module
ngx_http_fastcgi_module
ngx_http_geo_module
ngx_http_gzip_module
ngx_http_limit_req_module
ngx_http_limit_zone_module
ngx_http_map_module
ngx_http_memcached_module
ngx_http_proxy_module
ngx_http_referer_module
ngx_http_rewrite_module
ngx_http_ssi_module
ngx_http_upstream_ip_hash_module
ngx_http_userid_module
上記以外に必要なモジュールがあれば<オプション>で指定する。オプションでは以下のモジュールが使用できる。
ngx_http_addition_module
ngx_http_dav_module
ngx_http_flv_module
ngx_http_gzip_static_module
ngx_http_image_filter_module
ngx_http_random_index_module
ngx_http_realip_module
ngx_http_secure_link_module
ngx_http_ssl_module
ngx_http_stub_status_module
ngx_http_sub_module
ngx_http_xslt_module
ここでは以下のモジュールを有効にする。
WebDAVサポート
--with-http_dav_module
SSLサポート
--with-http_ssl_module
また、デフォルトで有効になるモジュールのうち必要ないものはあらかじめ無効にしておくことでパフォーマンスアップが図れる。
% make % sudo make install
インストール物 (man,infoは除く)
/usr/local/nginx/*/*
各種設定
/usr/local/nginx/conf/nginx.confにて基本的な設定を行う。
以下、主な設定項目について説明する。パスを設定するところで相対パスを指定した場合は/usr/local/nginxが起点となる。
サーバの待ち受けポート
http {
:
server {
listen 80;
サーバルート
http {
:
server {
:
location / {
root html;
インデックスファイル
リクエストが「/」で終わっている場合にインデックスファイルとして検索するファイルを指定する。
http {
:
server {
:
location / {
:
index index.html index.htm;
動作確認
デーモンを起動する。
% sudo /usr/local/nginx/sbin/nginx
待ち受けポートがLISTENになっているか確認する。
% netstat -nat|egrep '(Proto|:80)' Proto 受信-Q 送信-Q 内部アドレス 外部アドレス 状態 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
WebブラウザでlocalhostにアクセスできればOKである。
デーモンを終了する。
単にkillすればよい。
% sudo killall nginx
initスクリプト設置
Debパッケージで配布されているスクリプトをインストールする。
% sudo aptitude download nginx % sudo dpkg -i nginx_0.6.35-0ubuntu1_i386.deb ./etc/init.d/nginx
デーモンのパス変更(/usr/sbin -> /usr/local/nginx/sbin)、及びPIDファイルの指定を削除する。
% sudo sed -i 's_/usr/sbin/nginx_/usr/local/nginx/sbin/nginx_' /etc/init.d/nginx % sudo sed -i 's_--pidfile __' /etc/init.d/nginx % sudo sed -i 's_-p /var/run/$NAME.pid __' /etc/init.d/nginx % sudo sed -i 's_/var/run/$NAME.pid __' /etc/init.d/nginx