CentOS6へのNginxのインストール

リポジトリ登録

以下の公式ページを参照のこと。

http://nginx.org/en/linux_packages.html#stable

# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm を取得中
警告: /var/tmp/rpm-tmp.KvHZao: ヘッダ V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
準備中...                ########################################### [100%]
   1:nginx-release-centos   ########################################### [100%]

リポジトリ設定の確認。

# cat /etc/yum.repos.d/nginx.repo 
# nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

インストール

普通にyumでインストールする。

# yum install -y nginx
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.grandcloud.cn
 * extras: mirrors.yun-idc.com
 * updates: mirrors.163.com
nginx                                                    | 2.9 kB     00:00     
nginx/primary_db                                         |  25 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 0:1.4.4-1.el6.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package        Arch            Version                    Repository      Size
================================================================================
Installing:
 nginx          x86_64          1.4.4-1.el6.ngx            nginx          311 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 311 k
Installed size: 770 k
Downloading Packages:
nginx-1.4.4-1.el6.ngx.x86_64.rpm                         | 311 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : nginx-1.4.4-1.el6.ngx.x86_64                                 1/1 
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
  Verifying  : nginx-1.4.4-1.el6.ngx.x86_64                                 1/1 

Installed:
  nginx.x86_64 0:1.4.4-1.el6.ngx                                                

Complete!
#

インストールするとOS起動時はデフォルトで起動されるようだ。今回はテストのために入れるだけなのでオフっておく。

# /sbin/chkconfig --list nginx
nginx          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
# /sbin/chkconfig --levels 2345 nginx off
# /sbin/chkconfig --list nginx
nginx          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
#

で、起動してみて http://localhost/ でアクセスしてみる。

# service nginx start
nginx を起動中:                                            [  OK  ]
# ps -ef | grep nginx
root      3915     1  0 14:25 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     3917  3915  0 14:25 ?        00:00:00 nginx: worker process                   
root      3927  3312  0 14:25 pts/0    00:00:00 grep nginx
# telnet localhost 80
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Server: nginx/1.4.4
Date: Mon, 23 Dec 2013 05:25:55 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 19 Nov 2013 12:11:13 GMT
Connection: close
ETag: "528b5561-264"
Accept-Ranges: bytes

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Connection closed by foreign host.
#

Thank you for using nginx.が表示されていれば大丈夫。なおデフォルトのドキュメントルートは、

# cat /etc/nginx/nginx.conf
conf.d/*.confを見ていることを確認。(Apacheと同じ感じ)# cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
....

のとおり/usr/share/nginx/html。なおライブラリは以下のもののみを組み込んでいる。

# ldd /usr/sbin/nginx
	linux-vdso.so.1 =>  (0x00007fff061ff000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003033000000)
	libcrypt.so.1 => /lib64/libcrypt.so.1 (0x000000303c800000)
	libpcre.so.0 => /lib64/libpcre.so.0 (0x0000003044c00000)
	libssl.so.10 => /usr/lib64/libssl.so.10 (0x0000003042400000)
	libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x000000303f000000)
	libdl.so.2 => /lib64/libdl.so.2 (0x0000003032c00000)
	libz.so.1 => /lib64/libz.so.1 (0x0000003033800000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003032400000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003032000000)
	libfreebl3.so => /lib64/libfreebl3.so (0x000000303cc00000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x0000003040800000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x000000303f400000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x000000303dc00000)
	libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x000000303e800000)
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x000000303ec00000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x000000303f800000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003034400000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003034000000)
#

参照は以下。

http://nomnel.net/blog/install-nginx-in-centos6-using-yum/