网络下载nginx源码包:

wget http://nginx.org/download/nginx-1.6.2.tar.gz

安装依赖:

yum install pcre-devel zlib-devel  ##本地的光盘作为yum源

安装nginx:

useradd -M -s /sbin/nologin nginx

tar zxvf nginx-1.6.2.tar.gz -C /usr/src/

cd /usr/src/nginx-1.6.2/

[root@www nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module   ##编译安装-指定家目录-指定用户-指定组-携带模块

 

[root@www nginx-1.6.2]# make &&make install

[root@www nginx-1.6.2]# ls /usr/local/nginx/  ##验证安装

conf  html  logs  sbin

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/  ##优化执行路径

ls -l /usr/local/sbin/

总用量 0

lrwxrwxrwx. 1 root root 27 12月 30 20:03 nginx -> /usr/local/nginx/sbin/nginx


启动nginx:

nginx   ##启动

netstat -utpln |grep nginx

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      8311/nginx    

访问测试:

/etc/init.d/iptables stop

setenforce 0


[root@www ~]# elinks  --dump  http://IP地址


添加nginx为系统服务:

vi /etc/init.d/nginx

#!/bin/bash

# chkconfig: - 99 20

# description: Nginx Server Control Script

NP="/usr/local/nginx/sbin/nginx"

NPF="/usr/local/nginx/logs/nginx.pid"

case "$1" in 

  start)

    $NP;

    if [ $? -eq 0 ] 

    then

      echo "nginx is starting!! "

    fi

  ;;

  stop)

    kill -s QUIT $(cat $NPF)

    if [ $? -eq 0 ]

    then

    echo "nginx is stopping!! "

    fi

  ;;

  restart)

    $0 stop

    $0 start

  ;;

  reload)

    kill -s HUP $(cat $NPF)

    if [ $? -eq 0 ]

    then

      echo "nginx config file is reload! "

    fi

  ;;

  *)

    echo "Usage: $0 {start|stop|restart|reload}"

    exit 1

esac

exit 0

:wq

chmod +x /etc/init.d/nginx 

chkconfig --add nginx

/etc/init.d/nginx restart

[root@www conf]# pwd

/usr/local/nginx/conf

[root@www conf]# vi nginx.conf  ##编辑配置文件在server中添加如下行:

    location /status {

        stub_status on;

        access_log off;

    } 

:wq


/etc/init.d/nginx restart

nginx is stopping!! 

nginx is starting!! 


访问测试:IE

http://ip地址/status