参考:http://serverfault.com/questions/114895/why-is-nginx-more-popular-than-lighttpd
nginxは軽量級のウェブサーバーで、ロードバランサーとしてもリバースプロキシーとしても使えるそうです。
http://articles.slicehost.com/2008/12/17/centos-installing-nginx-via-yum
によるとEPELにもパッケージがあるそうなのですが、
http://download.fedora.redhat.com/pub/epel/5/x86_64/repoview/nginx.html
バージョン0.6.39と古いのでnginxホームページからソースを落としてインストールすることにします。
NginxHttpSslModuleによるとSSLを使うにはconfigureで--with-http_ssl_moduleオプションを指定しておく必要があります。
$ wget http://sysoev.ru/nginx/nginx-0.8.50.tar.gz
$ sudo yum install openssl-devel pcre-devel
$ tar zxf nginx-0.8.50.tar.gz
$ cd nginx-0.8.50
$ ./configure --with-http_ssl_module
$ make
$ sudo /usr/local/sbin/checkinstall
Requiresにopenssl, pcreを追加
$ sudo rpm -i /usr/src/redhat/RPMS/x86_64/nginx-0.8.50-1.x86_64.rpm
http://articles.slicehost.com/2009/2/20/centos-nginx-configurationと
http://503.mydns.jp/2010/06/nginx/
を参考にしつつ設定。
iptables設定
# /sbin/iptables -A RH-Firewall-1-INPUT -p tcp -m tcp --dport 80 -j ACCEPT
# /sbin/iptables -A RH-Firewall-1-INPUT -p tcp -m tcp --dport 443 -j ACCEPT
# /etc/init.d/iptables save
# /etc/init.d/iptables restart
グループとユーザ作成
# /usr/sbin/groupadd -g 201 nginx
# /usr/sbin/useradd -u 201 -g nginx -d / -s /sbin/nologin nginx
# mkdir /usr/local/nginx/conf.d
# mkdir /var/log/nginx
# vi /usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /usr/local/nginx/conf.d/*.conf;
server {
listen 80;
server_name sunshine12;
location / {
root /usr/local/nginx/html;
index index.html index.htm;
}
}
server {
listen 443 ssl;
ssl_certificate /usr/local/nginx/conf/server.crt;
ssl_certificate_key /usr/local/nginx/conf/server.key;
server_name sunshine12;
location / {
root /usr/local/nginx/html;
index index.html index.htm;
}
}
}
# vi /etc/init.d/nginx
#!/bin/bash
#
# nginx Startup script for the nginx Web Server
#
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Path
nginx='/usr/local/nginx/sbin/nginx'
prog=nginx
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon $nginx
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $nginx
RETVAL=$?
echo
return $RETVAL
}
reload() {
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|reload}"
exit 1
;;
esac
exit $RETVAL
# chmod +x /etc/init.d/nginx