系统环境 centos6.5 x64 mini

关闭防火墙

关闭selinux

 

开始安装nginx

创建用户

[root@zabbix-server sbin]# useradd -M nginx -s /sbin/nologin

 

安装环境需要的包

  

yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

 

wget  http://120.52.73.43/jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
wget  https://www.openssl.org/source/openssl-1.0.2h.tar.gz
wget  http://zlib.net/zlib-1.2.8.tar.gz
wget  http://nginx.org/download/nginx-1.10.0.tar.gz


这里下载的包,解压的位置和下面配置参数路径要一致。


解压安装nginx包

  tar -zxvf nginx-1.10.0.tar.gz
  cd nginx-1.10.0

配置

./configure \
–prefix=/usr/local/nginx \
–lock-path=/usr/local/nginx/nginx.lock \
–user=nginx \
–group=nginx \
–http-client-body-temp-path=/usr/local/nginx/client/ \
–http-proxy-temp-path=/usr/local/nginx/proxy/ \
–http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \
–http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
–http-scgi-temp-path=/usr/local/nginx/scgi \
–with-http_ssl_module \
–with-http_flv_module \
–with-http_mp4_module \
–with-http_gunzip_module \
–with-http_ssl_module \
–with-http_flv_module \
–with-http_stub_status_module \
–with-http_gzip_static_module \
–with-file-aio \
–with-http_p_w_picpath_filter_module \
–with-http_realip_module \
–with-pcre=/tar/pcre-8.38 \
–with-stream \
–with-openssl=/tar/openssl-1.0.2h \
–with-zlib=/tar/zlib-1.2.8

 

编译 && 编译安装

make && make install

 

启动nginx

/usr/local/nginx/sbin/nginx

 

创建启动停止脚本

vim /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
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ “$NETWORKING” = “no” ] && exit 0
 
nginx=”/usr/local/nginx/sbin/nginx”
prog=$(basename $nginx)
 
NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”
 
lockfile=/usr/local/nginx/nginx.lock
 
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

 

查看器启动状态

netstat -anpt  |grep 80
tcp    0      0 0.0.0.0:80         0.0.0.0:*        LISTEN      6217/nginx

 


可以做一个软连接,不用全路径方式启动直接输入nginx 命令即可

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

或者编辑/etc/profile 文件

vim /etc/profile
最下面添加:
export PATH=$PATH:/usr/local/nginx/sbin


访问测试

http://ip地址