一.Nginx 安装以及配置

wget http://netix.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
wget http://jaist.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

./configure 
--prefix=/usr/local/nginx1.8 
--user=www 
--group=www 
--with-openssl=/root/Source/nginx/openssl-1.0.1c #源码包
--with-zlib=/root/Source/nginx/zlib-1.2.8        #源码包
--with-pcre=/root/Source/Apache2.4.18/pcre-8.38  #源码包

make && make install

启动 nginx

/usr/local/nginx1.8/sbin/nginx -c /usr/local/nginx1.8/conf/nginx.conf

多站点配置方法

创建所有虚拟站点的配置目录

mkdir /usr/local/nginx1.8/conf/include

配置多个站点方法
假设配置站点www.abc.com

vim www.abc.com_nginx_conf
server {
        listen 80;
        server_name www.abc.com;
        error_log  logs/www.abc.com.error.log;
        access_log logs/www.abc.com.access.log;
        index index.html index.php index.htm default.html default.htm default.php;
        root /www/abc_com;

        if (-d $request_filename){
            rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|css|js)$ {
                root /www/abc_com;
                if (-f $request_filename) {
                  expires 1s;
                  break;
                }

        }
        location ~ .*\.(html|htm)?$ {
                fastcgi_pass  127.0.0.1:9001;
                fastcgi_index index.html;
                include /usr/local/nginx1.8/conf/fastcgi.conf;
        }

        location ~ .*\.(php|php5)?$ {
                fastcgi_pass  127.0.0.1:9001;
                fastcgi_index index.php;
                fastcgi_param  PHP_VALUE  "open_basedir=/www/abc_com:/tmp/";
                include /usr/local/nginx1.8/conf/fastcgi.conf;
        }
}

如果多个项目则保存不同的文件

在项目主配置文件中配置如下

vim /usr/local/nginx1.8/conf/nginx.conf
在 http{...} 段最底部增加
include /usr/local/nginx1.8/conf/include/*;

即可

二. 关闭当前启动的nginx服务器

ps -ef | grep nginx | awk '{print $2}' | kill -9 或者
sudo kill `cat /usr/local/nginx1.8/logs/nginx.pid`

三. nginx服务重启脚本 vi /etc/init.d/nginx

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx1.8/conf/nginx.conf
# pidfile:     /usr/local/nginx1.8/logs/nginx.pid
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx1.8/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx1.8/conf/nginx.conf"

lockfile=/usr/local/nginx1.8/conf/nginx_lockfile

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
    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

使用方法:

/etc/init.d/nginx start|stop|status|restart

三. 设置nginx 开机启动

chmod +x /etc/init.d/nginx
/sbin/chkconfig nginx on

检查一下
sudo /sbin/chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off