CentOS 6.5 源码安装Nginx1.6.3

2 篇文章 0 订阅
一、软件配置信息
CentOS 6.5
nginx-1.6.3.tar.gz
二、必要软件准备
检查安装pcre,openssl,gzip命令如下:
yum install zlib zlib-devel pcre pcre-devel openssl openssl-devel
三、创建Nginx用户与组
[root@localhost src]# groupadd nginx
[root@localhost src]# useradd -r -g nginx -s /sbin/nologin -M nginx
四、下载解压
Nginx可以从官网下载:http://nginx.org/ 
也可以通过命令直接下载,我的当前目录是/usr/local/src:
[root@localhost src]# wget http://nginx.org/download/nginx-1.6.3.tar.gz
解压:
[root@localhost src]# tar zxvf nginx-1.6.3.tar.gz 
[root@localhost src]# cd nginx-1.6.3
五、开始安装
[root@localhost src]# cd nginx-1.6.3
[root@localhost nginx-1.6.3]#  ./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx  \
--conf-path=/etc/nginx/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

[root@localhost nginx-1.6.3]# make
[root@localhost nginx-1.6.3]# make install
六、启动停止
启动命令:
[root@localhost nginx-1.6.3]# /usr/sbin/nginx
 
    测试,直接用curl命令读取web信息: 
   
[root@localhost sbin]# curl -s http://localhost | grep nginx.com
关闭命令:
[root@localhost nginx-1.6.3]# /usr/sbin/nginx -s stop
reload,当你修改配置时,用此命令不用再重启就生效了:
[root@localhost 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
修改文件权限:
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
如果出现下面文字:
service nginx supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add nginx')
执行以下命令即可:
chkconfig --add nginx





  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nginx(发音同engine x)是一款由俄罗斯程序员Igor Sysoev所开发轻量级的网页服务器、反向代理服务器以及电子邮件(IMAP/POP3)代理服务器。起初是供俄国大型的门户网站及搜索引擎Rambler(俄语:Рамблер)使用。此软件BSD-like协议下发行,可以在UNIX、GNU/Linux、BSD、Mac OS X、Solaris,以及Microsoft Windows等操作系统中运行。 nginx不单可以作为强大的web服务器,也可以作为一个反向代理服务器,而且nginx还可以按照调度规则实现动态、静态页面的分离,可以按照轮询、ip哈希、URL哈希、权重等多种方式对后端服务器做负载均衡,同时还支持后端服务器的健康检查。 Nginx负载均衡一些基础知识: nginx 的 upstream目前支持 4 种方式的分配 1)、轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。 2)、weight 指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。 2)、ip_hash 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。 3)、fair(第三方) 按后端服务器的响应时间来分配请求,响应时间短的优先分配。 4)、url_hash(第三方) 按访问的url的hash结果分配,使每个url定向到同一个后端服务器,后端为缓存服务器比较有效。 Nginx 截图: Nginx 更新日志: Nginx 1.6.0 稳定版发布,该版本包含很多来自 1.5.x 的新特性,包括各种 SSL 的提升、SPDY 3.1 支持、根据请求条件对缓存重新验证、认证请求模块等等。 SEnginx主线版本1.6.0发布,主要变更如下: Changes with senginx 1.6.0 14 May 2014 *) Feature: 升级到nginx 1.6.0 *) Feature: dynamic resolve功能增强,增加了设置DNS查询失败时的动作等功能 *) Feature: ngx_http_statistics模块,支持对流量和攻击的统计 *) Feature: http://demo.senginx.org ,用于演示ngx_http_statistics模块 *) Feature: 升级ModSecurity到2.8.0版本 *) Bugfix: 修改了cookie防篡改模块的若干bug

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值