- 追加された行はこの色です。
- 削除された行はこの色です。
[[さくらのVPS]]
#contents
* nginxとは? [#n459f414]
Nginxは、最近人気のWebサーバソフトです。Apacheの代わりに使われだしています。
[[nginx - Wikipedia>http://ja.wikipedia.org/wiki/Nginx]]
>nginx(「エンジンエックス」と発音) は、軽量高性能なWebサーバ/リバースプロキシであり、同時に電子メール(IMAP/POP3)プロキシである。BSD系ライセンスでリリースされている。Unix系、Linux、BSD系、Mac OS X、Solaris、Microsoft Windows(Cygwinを使用)で動作する。
* リンク [#r8193825]
- 公式サイト(英語)
http://www.nginx.org/
- wiki(日本語)
http://wiki.nginx.org/NginxJa
- forum(英語)
http://forum.nginx.org/
* インストール [#lfa32964]
* 参考書 [#aabfd690]
#html{{
<table border="0" cellpadding="5"><tr><td valign="top">
<a href="http://www.amazon.co.jp/exec/obidos/ASIN/4048702270/sagasite-22/" target="_blank"><img src="http://ecx.images-amazon.com/images/I/51xpswg%2BkkL._SL160_.jpg" border="0"></a>
</td>
<td valign="top">
<a href="http://www.amazon.co.jp/exec/obidos/ASIN/4048702270/sagasite-22/" target="_blank">ハイパフォーマンスHTTPサーバ Nginx入門</a>
<br>
Clement Nedelcu<br>
アスキー・メディアワークス<br>
2011-04-21<br>
3150円
</td></tr></table>
}}
* インストール [#l2bc77da]
Nginxを、CentOSに、ソースコードからコンパイルして、手動でインストールする手順のまとめ
(参考)
CentOSにNginxをインストールする | HAPPY*TRAP
http://www.happytrap.jp/blogs/2012/02/23/8243/
** ダウンロード [#j8a1cba0]
** ダウンロード [#g8692e34]
''Nginx最新安定版(stable)を公式サイトからダウンロードします。''
+ Nginx最新安定版のバージョンを公式サイトで確認します。
http://nginx.org/en/download.html
(例) Stable version nginx-1.2.6
+ 作業ディレクトリ(tmp)に移動します。
$ cd /tmp
+ 圧縮ファイルをダウンロードします。
$ wget http://nginx.org/download/nginx-1.2.6.tar.gz
(wgetコマンドがインストールされていない場合は、「sudo yum install wget」)
+ ダウンロードしたファイルを解凍します。
$ tar zxf nginx-1.2.6.tar.gz
+ カレントディレクトリを移動します。
$ cd nginx-1.2.6
** コンパイル [#za02b0b2]
** コンパイル [#v4b57607]
+ Nginx用のユーザーを作成します。
$ sudo useradd -s/sbin/nologin -d/usr/local/nginx -M nginx
+ Nginxに必要なライブラリをインストールします。
(例では、必須ライブラリの他にHTTPSのコンテンツを処理するOpenSSLライブラリもインストールしています。)
$ sudo yum install gcc
$ sudo yum install pcre pcre-devel
$ sudo yum install zlib zlib-devel
$ sudo yum install openssl openssl-devel
+ 使用するオプションを付けてconfigureを実行します。
$ ./configure --prefix=/usr/local/nginx-1.2.6 --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module
+ コンパイルして、インストールします。
$ make
$ sudo make install
** シンボリックリンクの作成 [#ac627acd]
** シンボリックリンクの作成 [#b778e349]
Nginxをバージョンアップするごとに異なるprefixを指定するので、変更をやりやすくするために、prefixのディレクトリを指すシンボリックリンクを作成します。
+ ln -s /usr/local/nginx-1.2.6 /usr/local/nginx
+Nginxをバージョンアップするごとに異なるprefixを指定するので、変更をやりやすくするために、prefixのディレクトリを指すシンボリックリンクを作成します。
ln -s /usr/local/nginx-1.2.6 /usr/local/nginx
* 設定 [#t691954e]
** 自動起動スクリプト [#p8c0dfcc]
* 自動起動スクリプト [#t5fb789b]
''Nginxをソースからインストールした場合は、起動スクリプトが作成されないので自作します。''
+ /etc/init.dにnginxのプログラム起動スクリプトのファイルを作成します。
# vi /etc/init.d/nginx
+ ファイル内容は、以下のようにします。
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
# cf. http://www.happytrap.jp/blogs/2012/02/23/8243/
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/usr/local/nginx/logs/nginx.lock
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
+ 起動スクリプトに実行権限を付与します。
$ sudo chmod +x /etc/init.d/nginx
+ 自動起動の設定をします。
$ sudo chkconfig --add nginx
$ sudo chkconfig nginx on
これで、serviceコマンドでも起動・終了・再起動が実行できるようになります。
+ 自動起動の設定(ランレベル)を確認します。
$ sudo chkconfig --list nginx
これで、
''nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off''
と表示されたらOKです。
* 基本操作 [#bbd40afa]
* 参考記事 [#n3313ddd]
- 設定ファイルの文法チェック
$ sudo service nginx configtest
- さくらVPS(CentOS)でnginxとPHPをいれてみた (2011-02-25)
http://huikmn.blogspot.com/2011/02/vpscentosnginxphp.html
- 起動
$ sudo service nginx start
- nginx + PHP (2011-02-21)
http://www.kazu.tv/blog/archives/001020.html
- 終了
$ sudo service nginx stop
- nginxでPHPを動かす (2009-10-16)
http://d.hatena.ne.jp/perezvon/20091016/1255713335
- 再起動
$ sudo service nginx restart
- さくら VPS の Ubuntu 10.04 に nginx + PHP(FastCGI) な Web サーバーを構築する (2010-10-24)
http://cho-co.be/blog/linux/sakura-vps-ubuntu-10-04-nginx-php-fastcgi-web-server/
- さくらのVPS CentOSでサーバ構築 21 ? Nginx (2010-10-23)
http://akibe.com/2010/10/centos-setup-21-nginx/