ubichupas.net

nginxをCentOS6.5にインストールする方法

nginx.orgのダウンロードページの一番下にRPMパッケージ配布元へのリンクがあります。 CentOS用の他にUbuntu用もあるみたいです。

CentOSの場合はyumリポジトリ(/etc/yum.repos.d/nginx.repo)を設定するためのRPMパッケージを入れてから、yumコマンドでnginx本体をインストールする手順になっています。
# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

# yum -y install nginx

nginx本体のRPMパッケージは以下にありましたので、こちらからダウンロードしてインストールしてもよいでしょう。
インストールと同時にnginxの実行ユーザー作成と自動起動の設定も済んでいましたので、とりあえず起動するだけでhttp://localhost/にアクセスできるようになります。 なおiptablesの設定はしてくれないため自分で行いましょう。
# tail -n1 /etc/passwd
nginx:x:498:498:nginx user:/var/cache/nginx:/sbin/nologin

# chkconfig | grep nginx
nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

# service nginx start


# vi /etc/sysconfig/iptables
> -A INPUT -p tcp --dport 80 -j ACCEPT

# service iptables restart

nginxの初期設定(/etc/nginx/conf.d/default.conf)にはWeb公開ディレクトリが存在せず、/usr/share/nginx/html/index.htmlを返しているだけのようです。

なので最期にWeb公開ディレクトリを設定して作業完了です。
# mkdir -p /var/www/test
# chown root:nginx /var/www/test
# chmod g+w /var/www/test

# cat <<EOF > /etc/nginx/conf.d/test.conf
> server {
>     listen          80;
>     server_name     192.168.0.10  192.168.0.10:80;
>     root            /var/www/test;
>
>     location / {
>         index       index.html  index.php;
>     }
> }
> EOF

# service nginx restart

server_nameは仮想ホストを使う際のポイントになるようですが、今は必要ないのでIPアドレスを書いておきます。