nginx1.0.5インストールメモ(さくらのVPS - CentOS5.5)
[mitsugeek@mitsugeek ~]$ sudo su - [root@mitsugeek ~]# yum install pcre-devel zlib-devel openssl-devel [root@mitsugeek ~]# cd /usr/local/src [root@mitsugeek src]# wget http://sysoev.ru/nginx/nginx-1.0.5.tar.gz [root@mitsugeek src]# tar xzvf nginx-1.0.5.tar.gz [root@mitsugeek nginx-1.0.5]# cd nginx-1.0.5 [root@mitsugeek nginx-1.0.5]# ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_gzip_static_module \ --http-log-path=/var/log/nginx/access.log \ --http-client-body-temp-path=/var/run/nginx/client/ \ --http-proxy-temp-path=/var/run/nginx/proxy/ \ --http-fastcgi-temp-path=/var/run/nginx/fcgi/ \ --http-uwsgi-temp-path=/var/run/nginx/uwsgi/ \ --http-scgi-temp-path=/var/run/nginx/scgi/ [root@mitsugeek nginx-1.0.5]# make [root@mitsugeek nginx-1.0.5]# make install
コンパイルオプションは、http://wiki.nginx.org/NginxInstallOptions のExample 3です。
ちなみにamazonLinuxのコンパイルオプションには沢山のwithが。。
[ec2-user@ip-10-156-17-167 ~]$ nginx -V nginx version: nginx/0.8.53 built by gcc 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) TLS SNI support enabled configure arguments: --user=nginx --group=nginx --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-file-aio --with-mail_ssl_module --with-ipv6 --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
init.dスクリプトの作成
[root@mitsugeek nginx-1.0.5]# vi /etc/init.d/nginx
amazon Linuxから下記スクリプトをコピーして張り付けちゃう。
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # 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/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx 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 retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest_q || configtest || return 6 stop start } reload() { configtest_q || configtest || return 6 echo -n $"Reloading $prog: " killproc $nginx -HUP echo } configtest() { $nginx -t -c $NGINX_CONF_FILE } configtest_q() { configtest >/dev/null 2>&1 } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } # Upgrade the binary with no downtime. upgrade() { local pidfile="/var/run/${prog}.pid" local oldbin_pidfile="${pidfile}.oldbin" configtest_q || configtest || return 6 echo -n $"Staring new master $prog: " killproc $nginx -USR2 retval=$? echo sleep 1 if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then echo -n $"Graceful shutdown of old $prog: " killproc -p ${oldbin_pidfile} -QUIT retval=$? echo return 0 else echo $"Something bad happened, manual intervention required, maybe restart?" return 1 fi } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; force-reload|upgrade) rh_status_q || exit 7 upgrade ;; reload) rh_status_q || exit 7 $1 ;; status|status_q) rh_$1 ;; condrestart|try-restart) rh_status_q || exit 7 restart ;; *) echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart}" exit 2 esac
実行権限の付与
[root@mitsugeek nginx-1.0.5]# chmod +x /etc/init.d/nginx
/etc/sysconfig/nginxも作成しておく
[root@mitsugeek nginx-1.0.5]# vi /etc/sysconfig/nginx
# Configuration file for the nginx service # set this to the location of the nginx configuration file NGINX_CONF_FILE=/etc/nginx/nginx.conf
useraddする
amazonLinuxだとシェルは/bin/falseになってましたが、ここではnologinとしました。
[root@mitsugeek nginx-1.0.5]# useradd -s /sbin/nologin nginx
起動
[root@mitsugeek nginx-1.0.5]# /etc/init.d/nginx start ||> アクセスするとWelcome to nginx!が表示されました。 **終了 >|| [root@mitsugeek nginx-1.0.5]# /etc/init.d/nginx stop ||> **chkconfig の登録 >|| [root@mitsugeek nginx-1.0.5]# /sbin/chkconfig --add nginx [root@mitsugeek nginx-1.0.5]# /sbin/chkconfig --level 345 nginx on
rebootして起動するか確認
[root@mitsugeek nginx-1.0.5]# reboot
何分かたってブラウザでアクセスしてみたら問題なく
Welcome to nginx!の文字が。