• linux 安装nginx


    1、下载nginx

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

    tar zxvf nginx-1.4.7.tar.gz

    2、开始安装

    进入目录:cd nginx-1.4.7

    ./configure

    如果提示 “./configure: error: the HTTP rewrite module requires the PCRE library.”,执行以下语句:

    yum -y install gcc pcre-devel openssl openssl-devel

    继续:

    ./configure

    成功的话,会看到 “Configuration summary” 这句话,恭喜了!

    继续:

    make

    make install

    默认安装到/usr/local/nginx/ 目录

    检查下配置:

    /usr/local/nginx/sbin/nginx -t

    执行:

    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

    关于把nginx安装为服务:

    在/etc/init.d/目录,添加nginx文件:vi /etc/init.d/nginx

    如下内容:

    #!/bin/bash
    # nginx Startup script for the Nginx HTTP Server
    # this script create it by jackbillow at 2007.10.15.
    # it is v.0.0.2 version.
    # if you find any errors on this scripts,please contact jackbillow.
    # and send mail to jackbillow at gmail dot com.
    #
    # chkconfig: - 85 15
    # description: Nginx is a high-performance web and proxy server.
    # It has a lot of features, but it's not for everyone.
    # processname: nginx
    # pidfile: /usr/local/nginx/logs/nginx.pid
    # config: /usr/local/nginx/conf/nginx.conf
    
    nginxd=/usr/local/nginx/sbin/nginx
    nginx_config=/usr/local/nginx/conf/nginx.conf
    nginx_pid=/usr/local/nginx/logs/nginx.pid
    
    RETVAL=0
    prog="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
    
    [ -x $nginxd ] || exit 0
    
    
    # Start nginx daemons functions.
    start() {
    
    if [ -e $nginx_pid ];then
    echo "nginx already running...."
    exit 1
    fi
    
    echo -n $"Starting $prog: "
    daemon $nginxd -c ${nginx_config}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
    return $RETVAL
    
    }
    
    
    # Stop nginx daemons functions.
    stop() {
    echo -n $"Stopping $prog: "
    killproc $nginxd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
    }
    
    
    # reload nginx service functions.
    reload() {
    
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
    
    }
    
    # See how we were called.
    case "$1" in
    start)
    start
    ;;
    
    stop)
    stop
    ;;
    
    reload)
    reload
    ;;
    
    restart)
    stop
    start
    ;;
    
    status)
    status $prog
    RETVAL=$?
    ;;
    *)
    echo $"Usage: $prog {start|stop|restart|reload|status|help}"
    exit 1
    esac
    
    exit $RETVAL

     

    最后:

    为nginx脚本添加权限
    chmod a+x /etc/init.d/nginx

    添加nginx服务
    chkconfig --add nginx
    chkconfig nginx on

    此时,就可以用类似:service nginx restart 来操作nginx了!

    最后一步:

    访问默认80端口,你能看到 “Welcome to nginx!” 这段话么?

  • 相关阅读:
    php实现求链表中倒数第k个节点
    在python正在使用mysql
    1002. 写这个号码 (20)(数学啊 ZJU_PAT)
    Lua 环境结构 --Linux
    Java程序猿JavaScript学习笔记(4——关闭/getter/setter)
    C/C++数据对齐汇总
    多线程
    11gRAC CHM 管理
    hdu 4059 The Boss on Mars(纳入和排除)
    模板方法模式分析、图表和基本代码
  • 原文地址:https://www.cnblogs.com/pzrr/p/3665402.html
Copyright © 2020-2023  润新知