
こんにちは!
いまさらですが、nginxを使ったwebアプリを動かしてみたので、ブログに載せておこうと思います...
まず、nginxって..
HTMLドキュメントや画像ファイルといった静的コンテンツを高速で配信し、消費メモリが少なく、リバースProxyやロードバランサーといった機能も有した注目の軽量Webサーバーです。
詳細はこちらを見て下さい
今回はお手軽なwebアプリとして、EC-CUBEがありましたので、
こちらを動かしたいと思います。
■環境
CentOS 6.5 (VirtualBox)
↑の環境は構築は省略..
1. nginxのインストール
nginxのインストールはCentOSのデフォルトのリポジトリにはないので、nginxが提供しているリポジトリを追加します。
# touch /etc/yum.repos.d/nginx.repo
# vim /etc/yum.repos.d/nginx.repo
上記を追加すればyumで拾えるようになります。
# yum install nginx
nginxのインストールはこれだけ..
2. php-fpmのインストール
# yum list | grep php-fpm
php-fpm.x86_64 5.3.3-27.el6_5 updates
# yum -y install php-fpm
php-fpmの設定ファイルを編集する。
- user = apache
+ user = nginx
- group = apache
+ group = nginx
3. nginxの設定ファイルを編集する
設定ファイルは
# cd /etc/nginx/conf.d/default.conf
デフォルトでは、ドキュメントルートが
/usr/share/nginx/html
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /var/www/html;
index index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
# error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
nclude fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
修正後は、Apacheと同様の流れで、再起動すればよいと考えていましたが、
nginxはrestartしても設定を再読み込みしてくず、reloadが必要..
# service nginx reload
後は、mysql-serverのインストールそすれば、EC-CUBEを動かす環境は出来上がり..
また、次回はEC-CUBEの設定や、nginxをリバースプロキシとして動作させる内容を
書きたいと思います...