zoukankan      html  css  js  c++  java
  • Nginx 安装

    安装编译用到的软件:

    yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel

    现在到http://nginx.org/en/download.html下载最新版本的Nginx并安装。

    ./configure \
    --user=www \
    --group=www \
    --prefix=/usr/local/nginx \
    --sbin-path=/usr/sbin/nginx \
    --conf-path=/usr/local/nginx/conf/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/log/run/nginx.pid \
    --lock-path=/var/lock/subsys/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_gzip_static_module \
    --with-http_stub_status_module \
    --with-http_perl_module \
    --add-module=/usr/local/src/nginx-accesskey-2.0.3 \
    --with-mail \
    --with-mail_ssl_module

    #--prefix=/usr/local/nginx \ change -> /data/www/

    更多的编译选项请参考:http://wiki.nginx.org/NginxInstallOptions

    创建www组、用户、Nginx 日志目录

    /usr/sbin/groupadd www 
    /usr/sbin/useradd www -g www -d /dev/null -s /sbin/nologin
    mkdir -p /var/log/nginx
    chmod +w /var/log/nginx
    chown -R www:www /var/log/nginx


    启动、停止、查看状态Nginx

    下载初始化脚本(注:该代码格式需要转换)

    wget http://www.centos.bz/wp-content/uploads/2011/07/nginx
    mv nginx /etc/rc.d/init.d/
    chmod 755 /etc/rc.d/init.d/nginx

    转换格式

    vi /etc/rc.d/init.d/nginx
    :set ff=unix

    :wq

    或者

    touch /etc/rc.d/init.d/nginx
    chmod 755 /etc/rc.d/init.d/nginx
    vi /etc/rc.d/init.d/nginx

    输入保存下面代码:

    #!/bin/sh
    #
    # nginx - this script starts and stops the nginx daemin
    #
    # chkconfig: - 85 15
    # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
    # proxy and IMAP/POP3 proxy server
    # processname: nginx
    # config: /usr/local/nginx/conf/nginx.conf
    # pidfile: /usr/local/nginx/logs/nginx.pid

    # Source function library.
    . /etc/rc.d/init.d/functions

    # Source networking configuration.
    . /etc/sysconfig/network

    # Check that networking is up.
    [ "$NETWORKING" = "no" ] && exit 0

    nginx="/usr/sbin/nginx"
    prog=$(basename $nginx)

    NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

    lockfile=/var/lock/subsys/nginx

    start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
    }

    stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
    }

    restart() {
    configtest || return $?
    stop
    start
    }

    reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
    }

    force_reload() {
    restart
    }

    configtest() {
    $nginx -t -c $NGINX_CONF_FILE
    }

    rh_status() {
    status $prog
    }

    rh_status_q() {
    rh_status >/dev/null 2>&1
    }

    case "$1" in
    start)
    rh_status_q && exit 0
    $1
    ;;
    stop)
    rh_status_q || exit 0
    $1
    ;;
    restart|configtest)
    $1
    ;;
    reload)
    rh_status_q || exit 7
    $1
    ;;
    force-reload)
    force_reload
    ;;
    status)
    rh_status
    ;;
    condrestart|try-restart)
    rh_status_q || exit 0
    ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
    exit 2
    esac



    Nginx加入chkconfig,并设置开机启动

    chkconfig --add nginx
    chkconfig nginx on


    启动、停止,查看状态的命令

    service nginx start
    service nginx stop
    service nginx status



  • 相关阅读:
    【书目20200917】影响力思维
    Spring AOP +自定义注解 + Spel表达式 实现审计日志
    SPRING BOOT 注解之OBJECTPROVIDER源码追踪
    Activiti~相关概念
    ELK~fluentd多行日志的收集
    k8s~向etc/hosts里添加内容
    maven~本地仓库的指定
    ssh~ Access denied问题解决
    MySQL如何绕过授予information_schema中对象时报ERROR 1044(4200)错误
    Zabbix如何监控SQL Server服务状态
  • 原文地址:https://www.cnblogs.com/shuaixf/p/2271356.html
Copyright © 2011-2022 走看看