Nginx(エンジンエックス)のインストール手順・方法

Nginx をインストールしたので、手順や方法をご紹介します。

Nginx

nginx(「エンジンエックス」と発音) は、軽量高性能なWebサーバ/リバースプロキシであり、同時に電子メール(IMAP/POP3)プロキシである。

・引用元:nginx – Wikipedia

インストール手順

■ GCC、PCRE、zlib、OpenSSLをインストール

まず、Nginxのコンパイルに必要なものをインストールします。

# yum -y install gcc
# yum -y install pcre pcre-devel
# yum -y install zlib zlib-devel
# yum -y install openssl openssl-devel

■ Nginxのインストール

yum でインストールできる最も新しいバージョンは nginx 0.8.54 みたいです。

ちなみに、安定版は nginx-1.0.4 が2011-06-01にリリースされたもので最新のものになります。

# yum info nginx
Available Packages
Name       : nginx
Arch       : x86_64
Version    : 0.8.54
Release    : 1.el5
Size       : 389 k
Repo       : epel
Summary    : Robust, small and high performance HTTP and reverse proxy server
URL        : http://nginx.net/
License    : BSD
Description: Nginx [engine x] is an HTTP(S) server, HTTP(S) reverse proxy and
           : IMAP/POP3 proxy server written by Igor Sysoev.

早速、インストールします。

# yum -y install nginx

ちゃんとインストールされているか確認します。

# nginx -v
nginx version: nginx/0.8.54

オプションは nginx -h で確認できます。

# nginx -h
nginx version: nginx/0.8.54
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
 
Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/share/nginx/)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file

例えば、どういう configure でインストールされたかは、 nginx -V で確認できます。

(読みやすくするため、configureオプションは改行して表示しています。)

# nginx -V
nginx version: nginx/0.8.54
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
TLS SNI support disabled
configure arguments:
--user=nginx
--group=nginx
--prefix=/usr/share/nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi
--pid-path=/var/run/nginx.pid
--lock-path=/var/lock/subsys/nginx
--with-http_ssl_module --with-http_realip_module
--with-http_addition_module
--with-http_xslt_module
--with-http_image_filter_module
--with-http_geoip_module
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-http_degradation_module
--with-http_stub_status_module
--with-http_perl_module --with-mail
--with-file-aio --with-mail_ssl_module
--with-ipv6
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

■ Serviceに登録、自動起動設定

# chmod +x /etc/rc.d/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on
# chkconfig --list nginx
nginx          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

インストール手順は以上です。