nginxの設定例
Windowsでテストする場合は、WiNGiNXを使いましょう。
nginx.confの一部
# 特別な理由がない限りrootにしないこと user [ユーザ名] [グループ名]; # サーバーのCPUのコア数を入れましょう。 worker_processes 2; # 開かれたプロセス毎のファイル識別子の最大値 # worker_connectionsよりも多くするべきです。 worker_rlimit_nofile 8192; pid /var/run/nginx.pid; events { # もしも、CPUのコア×8000以上の接続がある場合、OSの最適化をすることを検討してください。 # ここの値はとても多くのリクエスト数を想定しています。 worker_connections 8000; # ここの設定は、リクエストのスマートキューイングを許可するかを設定します。 # worker_processesよりも多い場合は、Onにすべきです。 accept_mutex off; # この設定はOSによります。デフォルトでnginxは、selectを選択します。 # しかし、大きな数のリクエストがあると、明示的にepollやkqueueを設定したほうが # 高速になります。 # use epoll; # enable for Linux 2.6+ # use kqueue; # enable for *BSD (FreeBSD, OS X, ..) } http { ## # 基本設定 ## # 静的ファイルをnginxで送る(必ずonにしてください) sendfile on; tcp_nopush off; # Comet/long-pollを多用する場合はoff推奨 tcp_nodelay on; # Comet/long-pollを多用する場合はon推奨 keepalive_timeout 10; types_hash_max_size 2048; # server_tokens off; ignore_invalid_headers on; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 4 2k; request_pool_size 4k; # server_names_hash_bucket_size 64; # server_name_in_redirect off; # 外部ファイルによるmime.type設定 include /etc/nginx/mime.types; # デフォルトの文字コード charset utf-8; # フォールバック時のデフォルトのMimeタイプ default_type application/octet-stream; ## # ログ設定 ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip設定 ## # 出力を圧縮して帯域を節約 gzip on; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 6; gzip_proxied any; gzip_types # text/htmlは、HttpGzipModuleによって常時圧縮されます。 text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; # 高圧縮されたjsもしくはcssが壊れないことを確認します。 # http://blog.leetsoft.com/2007/7/25/nginx-gzip-ssl gzip_buffers 16 8k; # gzipを無効化するブラウザ gzip_disable “MSIE [1-6].(?!.*SV1)”; ## # nginx-naxsi config ## # nginx-naxsiがインストールされている場合コメントアウト ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # nginx-passengerがインストールされている場合コメントアウト ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # 仮想ホスト設定 ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
汎用Behavior設定(behavior.conf)
location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } location ~ \.cgi$ { fastcgi_split_path_info ^(.+\.cgi)(/.+)$; gzip off; # CGIでgzip有効化すると動作が遅くなるため、off推奨 fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_index index.cgi; include fastcgi_params; } location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ { expires 7d; access_log off; }
バーチャルホスト設定
PukiWiki Adv.使用時は、以下の設定を推奨します。
server{ listen 80; server_name [ホスト名]; root [ドキュメントルート]; index index.php; include behavior.conf; location / { error_page 404 = @pukiwiki; log_not_found off; } location @pukiwiki { rewrite ^/(.+)/$ /index.php?$1 last; rewrite ^/(.+)$ /index.php?$1 last; } }