zoukankan      html  css  js  c++  java
  • centos7 编译安装nginx

    nginx安装文档

    下载nginx及依赖库并解压缩

    • nginx,http://nginx.org/download/nginx-1.17.2.tar.gz
    • pcre库,https://jaist.dl.sourceforge.net/project/pcre/pcre2/10.33/pcre2-10.33.tar.gz
    • zlib库,http://117.128.6.17/cache/www.zlib.net/zlib-1.2.11.tar.gz
    • openssl库,https://www.openssl.org/source/openssl-1.1.1c.tar.gz
    • libatomic库,https://github.com/ivmai/libatomic_ops/releases/download/v7.6.10/libatomic_ops-7.6.10.tar.gz

    安装依赖软件

    sudo yum install pcre-devel
    sudo yum install gd-deval
    sudo yum install geoip-devel
    sudo yum install gperftools-devel
    sudo yum install gcc gcc-c++
    sudo yum install net-tools
    

    编译nginx

    sudo ./configure --prefix=/usr/local/nginx 
    --with-threads 
    --with-file-aio 
    --with-http_ssl_module 
    --with-http_v2_module 
    --with-http_realip_module 
    --with-http_addition_module 
    --with-http_image_filter_module 
    --with-http_geoip_module 
    --with-http_sub_module 
    --with-http_dav_module 
    --with-http_flv_module 
    --with-http_mp4_module 
    --with-http_gunzip_module 
    --with-http_gzip_static_module 
    --with-http_auth_request_module 
    --with-http_random_index_module 
    --with-http_secure_link_module 
    --with-http_degradation_module 
    --with-http_slice_module 
    --with-http_stub_status_module 
    --with-mail 
    --with-mail_ssl_module 
    --with-stream 
    --with-stream_ssl_module 
    --with-stream_realip_module 
    --with-stream_geoip_module 
    --with-stream_geoip_module=dynamic 
    --with-stream_ssl_preread_module 
    --with-google_perftools_module 
    --with-pcre 
    --with-pcre=/usr/local/src/pcre-8.43 
    --with-pcre-jit 
    --with-zlib=/usr/local/src/zlib-1.2.11 
    --with-openssl=/usr/local/src/openssl-1.1.1c 
    --with-debug
    

    nginx管理脚本

    #! /bin/sh
    # chkconfig: 2345 55 25
    # Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
    # run 'update-rc.d -f nginx defaults', or use the appropriate command on your
    # distro. For CentOS/Redhat run: 'chkconfig --add nginx'
    
    ### BEGIN INIT INFO
    # Provides:          nginx
    # Required-Start:    $all
    # Required-Stop:     $all
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts the nginx web server
    # Description:       starts nginx using start-stop-daemon
    ### END INIT INFO
    
    # Author:   licess
    # website:  https://lnmp.org
    
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    NAME=nginx
    NGINX_BIN=/usr/local/nginx/sbin/$NAME
    CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
    PIDFILE=/usr/local/nginx/logs/$NAME.pid
    if [ -s /bin/ss ]; then
        StatBin=/bin/ss
    else
        StatBin=/bin/netstat
    fi
    
    
    case "$1" in
        start)
            echo -n "Starting $NAME... "
    
            if $StatBin -tnpl | grep -q nginx;then
                echo "$NAME (pid `pidof $NAME`) already running."
                exit 1
            fi
    
            $NGINX_BIN -c $CONFIGFILE
    
            if [ "$?" != 0 ] ; then
                echo " failed"
                exit 1
            else
                echo " done"
            fi
            ;;
    
        stop)
            echo -n "Stoping $NAME... "
    
            if ! $StatBin -tnpl | grep -q nginx; then
                echo "$NAME is not running."
                exit 1
            fi
    
            $NGINX_BIN -s stop
    
            if [ "$?" != 0 ] ; then
                echo " failed. Use force-quit"
                $0 force-quit
            else
                echo " done"
            fi
            ;;
    
        status)
            if $StatBin -tnpl | grep -q nginx; then
                PID=`pidof nginx`
                echo "$NAME (pid $PID) is running..."
            else
                echo "$NAME is stopped."
                exit 0
            fi
            ;;
    
        force-quit|kill)
            echo -n "Terminating $NAME... "
    
            if ! $StatBin -tnpl | grep -q nginx; then
                echo "$NAME is is stopped."
                exit 1
            fi
    
            kill `pidof $NAME`
    
            if [ "$?" != 0 ] ; then
                echo " failed"
                exit 1
            else
                echo " done"
            fi
            ;;
    
        restart)
            $0 stop
            sleep 1
            $0 start
            ;;
    
        reload)
            echo -n "Reload service $NAME... "
    
            if $StatBin -tnpl | grep -q nginx; then
                $NGINX_BIN -s reload
                echo " done"
            else
                echo "$NAME is not running, can't reload."
                exit 1
            fi
            ;;
    
        configtest)
            echo -n "Test $NAME configure files... "
    
            $NGINX_BIN -t
            ;;
    
        *)
            echo "Usage: $0 {start|stop|restart|reload|status|configtest|force-quit|kill}"
            exit 1
            ;;
    
    esac
    

    将nginx添加到系统服务

    sudo chkconfig --add nginx
    sudo chkconfig --level 345 nginx on
    
    #现在就可以使用系统管理命令来使用nginx了
    sudo service nginx start|stop|reload|configtest|status
    or
    sudo systemctl start|stop|reload|configtest|status nginx
    

    使用systemd管理nginx启动脚本

    #Save this file as /lib/systemd/system/nginx.service
    
    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=syslog.target network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
  • 相关阅读:
    编码 unicode与utf8
    For WeiWei Server Code
    C#枚举
    一些关于java的笔记
    当众讲话第三章当众讲话的语言要求
    当众讲话第四章当众讲话出彩的资本
    会计要素和会计平衡公式
    当众讲话第一章 当众讲话的八项训练
    金蝶KIS标准版会计软件简单使用
    做事的科学细节与流程》读书笔记第一章
  • 原文地址:https://www.cnblogs.com/super-lulu/p/11349584.html
Copyright © 2011-2022 走看看