Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1155943
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: LINUX

2012-01-28 10:55:45

Installing the nginx

yum install gcc openssl-devel pcre-devel zlib-devel 

# groupadd nginx
# useradd -g nginx -s /bin/false -M nginx

./configure \
  --prefix=/usr \
  --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 \
  --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_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  --with-pcre

make && make install

启动脚本 :放在/etc/init.d/nginx并加入以下内容:
  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemon
  4. #
  5. # chkconfig: - 85 15
  6. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  7. # proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config: /etc/nginx/nginx.conf
  10. # config: /etc/sysconfig/nginx
  11. # pidfile: /var/run/nginx.pid
  12.  
  13. # Source function library.
  14. . /etc/rc.d/init.d/functions
  15.  
  16. # Source networking configuration.
  17. . /etc/sysconfig/network
  18.  
  19. # Check that networking is up.
  20. [ "$NETWORKING" = "no" ] && exit 0
  21.  
  22. nginx="/usr/sbin/nginx"
  23. prog=$(basename $nginx)
  24.  
  25. NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  26.  
  27. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  28.  
  29. lockfile=/var/lock/subsys/nginx
  30.  
  31. make_dirs() {
  32.    # make required directories
  33.    user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
  34.    options=`$nginx -V 2>&1 | grep 'configure arguments:'`
  35.    for opt in $options; do
  36.        if [ `echo $opt | grep '.*-temp-path'` ]; then
  37.            value=`echo $opt | cut -d "=" -f 2`
  38.            if [ ! -d "$value" ]; then
  39.                # echo "creating" $value
  40.                mkdir -p $value && chown -R $user $value
  41.            fi
  42.        fi
  43.    done
  44. }
  45.  
  46. start() {
  47.     [ -x $nginx ] || exit 5
  48.     [ -f $NGINX_CONF_FILE ] || exit 6
  49.     make_dirs
  50.     echo -n $"Starting $prog: "
  51.     daemon $nginx -c $NGINX_CONF_FILE
  52.     retval=$?
  53.     echo
  54.     [ $retval -eq 0 ] && touch $lockfile
  55.     return $retval
  56. }
  57.  
  58. stop() {
  59.     echo -n $"Stopping $prog: "
  60.     killproc $prog -QUIT
  61.     retval=$?
  62.     echo
  63.     [ $retval -eq 0 ] && rm -f $lockfile
  64.     return $retval
  65. }
  66.  
  67. restart() {
  68.     configtest || return $?
  69.     stop
  70.     sleep 1
  71.     start
  72. }
  73.  
  74. reload() {
  75.     configtest || return $?
  76.     echo -n $"Reloading $prog: "
  77.     killproc $nginx -HUP
  78.     RETVAL=$?
  79.     echo
  80. }
  81.  
  82. force_reload() {
  83.     restart
  84. }
  85.  
  86. configtest() {
  87.   $nginx -t -c $NGINX_CONF_FILE
  88. }
  89.  
  90. rh_status() {
  91.     status $prog
  92. }
  93.  
  94. rh_status_q() {
  95.     rh_status >/dev/null 2>&1
  96. }
  97.  
  98. case "$1" in
  99.     start)
  100.         rh_status_q && exit 0
  101.         $1
  102.         ;;
  103.     stop)
  104.         rh_status_q || exit 0
  105.         $1
  106.         ;;
  107.     restart|configtest)
  108.         $1
  109.         ;;
  110.     reload)
  111.         rh_status_q || exit 7
  112.         $1
  113.         ;;
  114.     force-reload)
  115.         force_reload
  116.         ;;
  117.     status)
  118.         rh_status
  119.         ;;
  120.     condrestart|try-restart)
  121.         rh_status_q || exit 0
  122.             ;;
  123.     *)
  124.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  125.         exit 2
  126. esac
    然后需要做的是:
          chkconfig --add nginx
          chkconfig nginx on





阅读(1232) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~