1. 下载 官网地址:http://nginx.org/ 
下载压缩包 http://nginx.org/download/nginx-1.8.0.tar.gz 
2. 加载linux光盘,配置仓库
[root@chen ~]# ls -l /dev|grep cdrom
lrwxrwxrwx. 1 root root           3 1月   3 20:55 cdrom -> sr0
crw-rw----. 1 root cdrom    21,   0 1月   3 20:55 sg0
brw-rw----. 1 root cdrom    11,   0 1月   3 20:55 sr0
[root@chen ~]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@chen ~]# cat /etc/yum.repos.d/CentOS-Media.repo 
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

3. 安装编译工具gcc等
[root@chen ~]# yum --disablerepo=\* --enablerepo=c6-media -y install gcc gcc-c++ autoconf automake
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
c6-media                                                           | 4.0 kB     00:00 ... 
包 gcc-4.4.7-11.el6.i686 已安装并且是最新版本
解决依赖关系
--> 执行事务检查
---> Package autoconf.noarch 0:2.63-5.1.el6 will be 安装
---> Package automake.noarch 0:1.11.1-4.el6 will be 安装
---> Package gcc-c++.i686 0:4.4.7-11.el6 will be 安装
--> 处理依赖关系 libstdc++-devel = 4.4.7-11.el6,它被软件包 gcc-c++-4.4.7-11.el6.i686 需要
--> 执行事务检查
---> Package libstdc++-devel.i686 0:4.4.7-11.el6 will be 安装
--> 完成依赖关系计算
... ... ... ...
已安装:
  autoconf.noarch 0:2.63-5.1.el6              automake.noarch 0:1.11.1-4.el6             
  gcc-c++.i686 0:4.4.7-11.el6                
作为依赖被安装:
  libstdc++-devel.i686 0:4.4.7-11.el6                                                     
完毕!

4. 安装zlib等支持库
[root@chen ~]# yum --disablerepo=\* --enablerepo=c6-media -y install zlib zlib-devel openssl openss-devel pcre-devel
已加载插件:fastestmirror, security
设置安装进程
... ... ... ...
已安装:
  pcre-devel.i686 0:7.8-6.el6                                                             
完毕!

5. 上传压缩包到服务器,解压
[root@chen ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  nginx-1.8.0.tar.gz
[root@chen ~]# tar -zxvf  nginx-1.8.0.tar.gz 
nginx-1.8.0/
nginx-1.8.0/auto/
nginx-1.8.0/conf/
... ... ... ...
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library
  nginx path prefix: "/usr"
  nginx binary file: "/usr/sbin/nginx"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/tmp/nginx/client"
  nginx http proxy temporary files: "/var/tmp/nginx/proxy"
  nginx http fastcgi temporary files: "/var/temp/nginx/fcgi"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

7. 编译内核
[root@chen nginx-1.8.0]# make && make install
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.8.0'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
		-o objs/src/core/nginx.o \
		src/core/nginx.c
... ... ... ...
make[1]: Leaving directory `/root/nginx-1.8.0'


8. 编写脚本nginx放入/etc/init.d/目录下:
#!/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/nginx.lock}
pidfile=${PIDFILE-/var/run/nginx/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

9. 测试
[root@chen ~]# chkconfig --add nginx
[root@chen ~]# chkconfig --list nginx
nginx          	0:关闭	1:关闭	2:启用	3:启用	4:启用	5:启用	6:关闭
[root@chen ~]# service nginx start
[root@chen ~]# service nginx stop
停止 nginx:                                               [确定]

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐