
せっかく自宅にサーバを構築するので、会社では触らないソフトを使用してみる企画。
第一回はWebサーバとしてnginx を取り上げます。
nginx(えんじん えっくす)はロシアの人が作っているWebサーバで、軽量高速が特徴らしい。 WordPressの本家 でも使っているようなので、相性も良いだろうと言う事で。
nginx をビルドする
tarball を取ってきて普通に configure, make, make install だけです。
tar zxvf nginx-0.6.32.tar.gz cd nginx-0.6.32 ./configure --with-openssl=/usr --with-http_stub_status_module make sudo paco -D make install
nginx の設定
nginx.conf というファイルを編集します。nginx には Apache の .htaccess に相当する設定ファイルは無いようなので、基本的には全ての設定はこのファイルに書く事になります。シンプルと言えばシンプルですが、複数の Virtual Host の設定を1つのファイルに記述すると見通しが悪くなるので、設定ファイルを複数のファイルに分けて nginx.conf から include する事もできるようになっています。
試行錯誤した結果、このサイトの現在の nginx.conf は下のようになっています。
user nobody;
worker_processes 3;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"';
access_log /var/log/nginx/access.log main;
rewrite_log on;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 4 8K;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 65;
client_max_body_size 10M;
# error catch
server {
listen 80;
server_name _;
root /var/www/temp;
index index.html;
auth_basic "secret";
auth_basic_user_file /var/www/htpasswd;
access_log /var/log/nginx/temp-access.log main;
}
# load the virtual server settings
include /usr/local/nginx/conf.d/*.conf;
}
細かい設定の話は次回

