Nginxの起動

rpmで一通りインストールされるので、サービス起動するだけでOK。ただし、既存のapacheがある場合、ポート番号がバッティングするので、/etc/nginx/nginx.confのlistenを8080とかに変更。


# service nginx start
nginx を起動中: [ OK ]
#

# netstat -nap|more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 2693/snmpd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2842/mysqld
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 3067/smbd
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 792/nginx.conf
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 3251/dnsmasq
tcp 0 0 221.186.158.42:53 0.0.0.0:* LISTEN 2555/named
tcp 0 0 10.1.208.21:53 0.0.0.0:* LISTEN 2555/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 2555/named
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 2914/postmaster
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2982/master
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 2555/named
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 3067/smbd
tcp 0 0 10.1.208.21:43523 10.1.204.54:445 ESTABLISHED 3094/winbindd
tcp 0 0 :::18080 :::* LISTEN 4013/java
tcp 0 0 :::80 :::* LISTEN 3035/httpd

一見起動しているように見せかけて実はエラー。原因はこれ。
# cat /var/log/nginx/error.log
2012/04/02 15:54:17 [emerg] 793#0: eventfd() failed (38: Function not implemented)
2012/04/02 15:54:17 [alert] 792#0: worker process 793 exited with fatal code 2 and can not be respawn

http://najeira.blogspot.jp/2011/01/nginxeventfd-failed.html
libaioとやらを入れて完了。とはいかず、はまる。

ここを参考に。この辺の手順はrpm/yumの恩恵を感じる。
http://www.kazu.tv/blog/archives/001012.html

# wget http://ftp.riken.jp/Linux/fedora/epel/5/SRPMS/nginx-0.8.55-1.el5.src.rpm
# yum list rpm-build

# diff -u /usr/src/redhat/SPECS/nginx.spec*

      • /usr/src/redhat/SPECS/nginx.spec 2012-04-02 16:33:41.000000000 +0900
      1. /usr/src/redhat/SPECS/nginx.spec.org 2012-04-02 16:32:19.000000000 +0900

@@ -96,6 +96,7 @@
--with-http_stub_status_module \
--with-http_perl_module \
--with-mail \

  1. --with-file-aio \

--with-mail_ssl_module \
--with-ipv6 \
--with-cc-opt="%{optflags} $(pcre-config --cflags)" \

# rpmbuild -bb /usr/src/redhat/SPECS/nginx.spec
エラー: ビルド依存性の失敗:
pcre-devel は nginx-0.8.55-1.i386 に必要とされています
openssl-devel は nginx-0.8.55-1.i386 に必要とされています
libxslt-devel は nginx-0.8.55-1.i386 に必要とされています
GeoIP-devel は nginx-0.8.55-1.i386 に必要とされています
gd-devel は nginx-0.8.55-1.i386 に必要とされています
# yum install pcre-devel openssl-devel libxslt-devel GeoIP-devel gd-devel --enablerepo=epel
GeoIP-develだけepel経由で入れたためバージョン不一致が起きるので。


# rpmbuild -bb /usr/src/redhat/SPECS/nginx.spec
・・・

  1. exit 0

# rpm -ivh /usr/src/redhat/RPMS/i386/nginx-0.8.55-1.i386.rpm
# service nginx start
nginx を起動中: [ OK ]

# telnet localhost 8080
Trying 127.0.0.1...
Connected to xen.tnc.local (127.0.0.1).
Escape character is '^]'.
HEAD / HTTP/1.0

HTTP/1.1 200 OK
Server: nginx/0.8.55
Date: Mon, 02 Apr 2012 08:02:13 GMT
Content-Type: text/html
Content-Length: 3698
Last-Modified: Tue, 30 Aug 2011 02:47:05 GMT
Connection: close
Accept-Ranges: bytes

Connection closed by foreign host.
#

ようやく起動した。