1、检测所需扩展是否都已安装:
1 rpm -qa | grep "pcre" 2 rpm -qa | grep "openssl" 3 rpm -qa | grep "wget" 4 rpm -qa | grep "zlib" 5 6 # 如果缺少某一扩展 用yum安装即可 7 yum install pcre* -y 8 yum install openssl* -y 9 yum install zlib -y 10 yum install zlib-devel -y
2、下载nginx安装包:
wget http://nginx.org/download/nginx-1.8.0.tar.gz
3、解压:
tar -zxvf nginx-1.8.0.tar.gz
4、安装:
1 cd nginx-1.8.0 2 ./configure --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log
--pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --user=www --group=www
--without-select_module --without-poll_module --with-file-aio --with-http_ssl_module
--with-http_realip_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --without-http_scgi_module
--without-http_memcached_module --without-http_limit_conn_module
--without-http_limit_req_module --http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/tmp/client-body-temp --http-proxy-temp-path=/tmp/proxy-temp
--http-fastcgi-temp-path=/tmp/fastcgi-temp --without-mail_pop3_module --without-mail_imap_module
--without-mail_smtp_module --add-module=../agentzh-headers-more-nginx-module-*/
3 make && make install
5、启动:
1 cd /usr/local/nginx/sbin 2 ./nginx 3 4 # 重新载入配置文件 5 ./nginx -s reload
6、添加到service 服务中:
1 # 首先在/usr/bin 目录下创建nginx 软连 2 cd /usr/bin 3 ln -s /usr/local/nginx/sbin/nginx nginx 4 5 # 编写nginx 启动shell 脚本 6 cd /etc/init.d 7 vim nginx 8 9 # 代码在下方
nginx 启动代码:

1 #!/bin/bash 2 ###################################################### 3 ## Modify by adam.li@ismole.com at 2012-07-20 13:52 ## 4 ## Compatible with RedHat/CentOS Debian/Ubuntu SUSE ## 5 ###################################################### 6 7 # Support chkconfig on RedHat/CentOS 8 # chkconfig: 2345 90 60 9 # description: nginx 10 # processname: nginx 11 # config: /usr/local/nginx/conf/nginx.conf 12 # pidfile: /var/run/nginx.pid 13 14 # Support Linux Standard Base Core Specification 3.2 15 ### BEGIN INIT INFO 16 # Provides: nginx 17 # Required-Start: $local_fs $syslog $network 18 # Required-Stop: 19 # Default-Start: 2 3 4 5 20 # Default-Stop: 0 S 1 6 21 # Short-Description: start/stop nginx daemon 22 # Description: nginx is a web server, http and mail proxy server 23 ### END INIT INFO 24 25 #debug 26 #set -x 27 #check unbound variables 28 #set -u 29 # Scripts PATH enviroment 30 export PATH="/usr/bin:/bin:/usr/sbin:/sbin" 31 # disable core dump 32 ulimit -c 0 33 # return value 34 RETVAL=0 35 # nginx general config 36 PROG="nginx" 37 SYMLINK=$(readlink -f /usr/local/nginx) 38 BASEDIR=${SYMLINK:-/usr/local/nginx} 39 DAEMON="${BASEDIR}/sbin/nginx" 40 CONF="${BASEDIR}/conf/nginx.conf" 41 PIDFILE="/var/run/${PROG}.pid" 42 LOCKFILE="/var/lock/$PROG" 43 # nginx start timeout milliscond 44 STARTTIME=10000 45 # nginx stop timeout milliscond 46 STOPTIME=10000 47 48 #Common Function 49 color_msg(){ 50 local COLOR=$1 51 local MSG=$2 52 OFFSET="