码迷,mamicode.com
首页 > 其他好文 > 详细

centos7.0 64位系统安装 nginx

时间:2015-10-31 16:55:24      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

                        1 下载nginx

                           从nginx官网 http://nginx.org/ 下载新的稳定版本nginx 并上传到linux服务器

                        2 安装nginx 所需要的扩展

                  yum -y install pcre openssl  openssl-devel

                         3 安装nginx

                         

                useradd -s /sbin/nologin www 
                tar zxvf nginx-1.8.0.tar.gz 
                cd nginx-1.8.0
                ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --without-http-cache --with-http_ssl_module 
--with-http_gzip_static_module make make install

                          配置nginx开机启动文件

                          vi  /etc/init.d/nginx 写入如下内容 根据实际情况修改

                          

#!/bin/sh
#
# nginx - this script start and stop the nginx daemon
#
# chkconfig: 2345 55 25
# description: Startup script for nginx
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /var/run/nginx.pid
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
                                                   
DAEMON=/usr/local/nginx/sbin/nginx
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/nginx.pid
SCRIPTNAME=/etc/init.d/nginx
LOCKFILE=/var/lock/nginx.lock
                                                   
set -e
[[ -x "$DAEMON" ]] || exit 0
                                                   
start() {
    echo "Startting Nginx......"
    [[ -x $DAEMON ]] || exit 5
    [[ -f $CONFIGFILE ]] || exit 6
    $DAEMON -c $CONFIGFILE || echo -n "Nginx already running!"
    [[ $? -eq 0 ]] && touch $LOCKFILE
}
                                                   
stop() {
    echo "Stopping Nginx......"
    MPID=`ps aux | grep nginx | awk /master/{print $2}`
                                                      
    if [[ "${MPID}X" != "X" ]]; then
        kill -QUIT $MPID
        [[ $? -eq 0 ]] && rm -f $LOCKFILE
    else
        echo "Nginx server is not running!"
    fi
}
                                                   
reload() {
    echo "Reloading Nginx......"
    MPID=`ps aux | grep nginx | awk /master/{print $2}`
                                                      
    if [[ "${MPID}X" != "X" ]]; then
        kill -HUP $MPID
    else
        echo "Nginx can‘t reload!"
    fi
}
                                                   
case "$1" in
start)
    start
    ;;
                                                      
stop)
    stop
    ;;
                                                      
reload)
    reload
    ;;
                                                      
restart)
    stop
    sleep 1
    start
    ;;
                                                      
*)
    echo "Usage: $SCRIPTNAME {start|stop|reload|restart}"
    exit 3
    ;;
esac
                                                   
exit 0

                       4 设置开机启动

                          

        chmod 755 /etc/init.d/nginx
              chkconfig --add nginx
              chkconfig  nginx on
              /etc/init.d/nginx start  

                       5 测试 用浏览器访问实际的域名 看看是否正常

                       6 重启服务器 看nginx 是否随机启动

centos7.0 64位系统安装 nginx

标签:

原文地址:http://www.cnblogs.com/jackspider/p/4925621.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!