CentOS 6.5 源碼安裝Nginx

來源:互聯網
上載者:User

標籤:nginx

一、軟體配置資訊

CentOS 6.5

二、必要軟體準備

檢查安裝pcre,openssl,gzip命令如下:

yum install -y zlib zlib-devel pcre pcre-devel openssl openssl-devel

三、建立Nginx使用者與組

[[email protected] src]# groupadd nginx  [[email protected] src]# useradd -r -g nginx -s /sbin/nologin -M nginx

四、下載解壓

Nginx可以從官網下載:http://nginx.org/ 

也可以通過命令直接下載,我的目前的目錄是/usr/local/src:

[[email protected] src]# wget http://nginx.org/download/nginx-1.10.1.tar.gz

解壓:

[[email protected] src]# tar zxvf nginx-1.10.1.tar.gz   [[email protected] src]# cd nginx-1.10.1

五、開始安裝

[[email protected] src]# cd nginx-1.6.3  [[email protected] nginx-1.6.3]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-file-aio --with-http_spdy_module --with-ipv6 --with-pcre   ./configure \  --prefix=/usr/local/nginx \  --sbin-path=/usr/sbin/nginx  \  --conf-path=/usr/local/nginx/conf/nginx.conf   \  --error-log-path=/var/log/nginx/error.log  \  --http-log-path=/var/log/nginx/access.log   \  --pid-path=/var/run/nginx.pid   \  --lock-path=/var/run/nginx.lock  \  --http-client-body-temp-path=/var/cache/nginx/client_temp  \  --http-proxy-temp-path=/var/cache/nginx/proxy_temp  \  --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp  \  --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp  \  --http-scgi-temp-path=/var/cache/nginx/scgi_temp  \  --user=nginx  \  --group=nginx   \  --with-http_ssl_module  \  --with-http_realip_module  \  --with-http_addition_module  \  --with-http_sub_module  \  --with-http_dav_module  \  --with-http_flv_module  \  --with-http_mp4_module  \  --with-http_gunzip_module  \  --with-http_gzip_static_module \  --with-http_random_index_module \  --with-http_secure_link_module \  --with-http_stub_status_module \  --with-http_auth_request_module  \  --with-file-aio  \  --with-http_spdy_module  \  --with-ipv6  \ --with-pcre    [[email protected] nginx-1.6.3]# make  [[email protected] nginx-1.6.3]# make install

六、啟動停止

啟動命令:

[[email protected] nginx-1.6.3]# /usr/sbin/nginx

測試,直接用curl命令讀取web資訊:

[[email protected] sbin]# curl -s http://localhost | grep nginx.com

關閉命令:

[[email protected] nginx-1.6.3]# /usr/sbin/nginx -s stop   reload,當你修改配置時,用此命令不用再重啟就生效了:[[email protected] nginx-1.6.3]# /usr/sbin/nginx -s reload

七、配置Nginx為系統服務
添加如下檔案:

vi /etc/init.d/nginx#!/bin/sh  #  # nginx        Startup script for nginx  #  # chkconfig: - 85 15  # processname: nginx  # config: /etc/nginx/nginx.conf  # config: /etc/sysconfig/nginx  # pidfile: /var/run/nginx.pid  # description: nginx is an HTTP and reverse proxy server  #  ### BEGIN INIT INFO  # Provides: nginx  # Required-Start: $local_fs $remote_fs $network  # Required-Stop: $local_fs $remote_fs $network  # Default-Start: 2 3 4 5  # Default-Stop: 0 1 6  # Short-Description: start and stop nginx  ### END INIT INFO    # Source function library.  . /etc/rc.d/init.d/functions    if [ -L $0 ]; then      initscript=`/bin/readlink -f $0`  else      initscript=$0  fi    sysconfig=`/bin/basename $initscript`    if [ -f /etc/sysconfig/$sysconfig ]; then      . /etc/sysconfig/$sysconfig  fi    nginx=${NGINX-/usr/sbin/nginx}  prog=`/bin/basename $nginx`  conffile=${CONFFILE-/etc/nginx/nginx.conf}  lockfile=${LOCKFILE-/var/lock/subsys/nginx}  pidfile=${PIDFILE-/var/run/nginx.pid}  SLEEPMSEC=${SLEEPMSEC-200000}  UPGRADEWAITLOOPS=${UPGRADEWAITLOOPS-5}  RETVAL=0    start() {      echo -n $"Starting $prog: "        daemon --pidfile=${pidfile} ${nginx} -c ${conffile}      RETVAL=$?      echo      [ $RETVAL = 0 ] && touch ${lockfile}      return $RETVAL  }    stop() {      echo -n $"Stopping $prog: "      killproc -p ${pidfile} ${prog}      RETVAL=$?      echo      [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}  }    reload() {      echo -n $"Reloading $prog: "      killproc -p ${pidfile} ${prog} -HUP      RETVAL=$?      echo  }  upgrade() {      oldbinpidfile=${pidfile}.oldbin        configtest -q || return      echo -n $"Starting new master $prog: "      killproc -p ${pidfile} ${prog} -USR2      echo        for i in `/usr/bin/seq $UPGRADEWAITLOOPS`; do          /bin/usleep $SLEEPMSEC          if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then              echo -n $"Graceful shutdown of old $prog: "              killproc -p ${oldbinpidfile} ${prog} -QUIT              RETVAL=$?              echo              return          fi      done        echo $"Upgrade failed!"      RETVAL=1  }  configtest() {      if [ "$#" -ne 0 ] ; then          case "$1" in              -q)                  FLAG=$1                  ;;              *)                  ;;          esac          shift      fi      ${nginx} -t -c ${conffile} $FLAG      RETVAL=$?      return $RETVAL  }    rh_status() {      status -p ${pidfile} ${nginx}  }    # See how we were called.  case "$1" in      start)          rh_status >/dev/null 2>&1 && exit 0          start          ;;      stop)          stop          ;;      status)          rh_status          RETVAL=$?          ;;      restart)          configtest -q || exit $RETVAL          stop          start          ;;      upgrade)          rh_status >/dev/null 2>&1 || exit 0          upgrade          ;;    condrestart|try-restart)          if rh_status >/dev/null 2>&1; then              stop              start          fi          ;;      force-reload|reload)          reload          ;;      configtest)          configtest          ;;      *)          echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"          RETVAL=2  esac    exit $RETVAL
  1. 修改檔案許可權:

chmod +x /etc/init.d/nginx

查看Nginx服務:

chkconfig --list nginx nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

本文出自 “IT·奮鬥” 部落格,謝絕轉載!

CentOS 6.5 源碼安裝Nginx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.