• 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!” 这段话么?

  • 相关阅读:
    Sign in with the app-specific password you generated. If you forgot the app-specific password or need to create a new one, go to appleid.apple.com
    Java Web项目搭建过程记录(struts2)
    微信小程序之菜鸟入门教学(二)
    微信小程序之菜鸟选手入门教学(一)
    html 表单input录入内容校验
    VUE中使用driver.js实现先手引导
    BScroll使用
    VUE使用screenfull实现全屏
    VUE打印功能
    VUE中使用XLSX实现导出excel表格
  • 原文地址:https://www.cnblogs.com/pzrr/p/3665402.html
Copyright © 2020-2023  润新知