zoukankan      html  css  js  c++  java
  • nginx安装与配置

    对于centos,

    首先,安装一些依赖:

    yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

    1创建并进入安装包存放目录

    mkdir nginx-src && cd nginx-src

    2 wget下载 nginx1.7 

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

    3 解压  

    tar xzf nginx-1.7.3.tar.gz

    4 进入并编译安装   

    cd nginx-1.7.3  

     ./configure  

     make  

     make install  

    5 nginx默认安装在/usr/local/nginx目录下

     whereis nginx  

    1. nginx: /usr/local/nginx 

    6.管理Nginx

    启动:/usr/local/nginx/sbin/nginx 

    nginx -s signal

    • stop — fast shutdown
    • quit — graceful shutdown
    • reload — reloading the configuration file
    • reopen — reopening the log files

    停止:nginx -s stop/quit

    重新加载:nginx -s reload

    当然也可以将nginx 加入系统服务

    在/etc/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/local/nginx/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

    赋予其可执行权限:

    chmod +x 

    chkconfig --add nginx

    之后就可使用service nginx start/stop/restart/reload/status管理nginx.

     访问 http://ip:80,如果出现如下欢迎页则一切成功,否则查看防火墙是否关闭或者拦截了80端口。

  • 相关阅读:
    浅析JNI
    网易云音乐歌词下载器
    如何用一个SQL“搞挂”一个服务模块
    SpingBoot 1.5.2,MultipartFile保存图片时的不稳定异常(好像和内置tomcat有关)
    double 去除小数点后的0
    项目中时间处理----今天:时分(10:15),昨天/前天:(昨天/前天),除此之外的本周(星期几),再往前年.月.日(2017.06.15)
    SpringMvc 静态内部类 封装请求数据
    jsp页面 ajax提交数组 到struts2的action
    Struts2 s:if test判断时遇到的问题
    Struts2中 iterator隔行变色
  • 原文地址:https://www.cnblogs.com/itdev/p/7004453.html
Copyright © 2011-2022 走看看