Alibaba Cloud Linux 3.2104 64位安裝nginx-1.16.1


    1   下載nginx

                           從nginx官網 http://nginx.org/ 下載新的穩定版本nginx 並上傳到linux服務器

               2  安裝nginx 所需要的擴展     

            yum -y install pcre openssl  openssl-devel

                3  安裝nginx

                useradd -s /sbin/nologin www 
                tar zxvf nginx-1.8.0.tar.gz 
                cd nginx-1.8.0
                ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --without-http-cache --with-http_ssl_module  --with-pcre=/home/www/pcre-8.31 (源文件的解壓路徑不是安裝路徑)                --with-http_gzip_static_module
                make 
                make install

       

                          配置nginx開機啟動文件

                          vi  /etc/init.d/nginx 寫入如下內容 根據實際情況修改

    

#!/bin/sh
#
# nginx - this script start and stop the nginx daemon
#
# chkconfig: 2345 55 25
# description: Startup script for nginx
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /var/run/nginx.pid
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
                                                   
DAEMON=/usr/local/nginx/sbin/nginx
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/nginx.pid
SCRIPTNAME=/etc/init.d/nginx
LOCKFILE=/var/lock/nginx.lock
                                                   
set -e
[[ -x "$DAEMON" ]] || exit 0
                                                   
start() {
    echo "Startting Nginx......"
    [[ -x $DAEMON ]] || exit 5
    [[ -f $CONFIGFILE ]] || exit 6
    $DAEMON -c $CONFIGFILE || echo -n "Nginx already running!"
    [[ $? -eq 0 ]] && touch $LOCKFILE
}
                                                   
stop() {
    echo "Stopping Nginx......"
    MPID=`ps aux | grep nginx | awk '/master/{print $2}'`
                                                      
    if [[ "${MPID}X" != "X" ]]; then
        kill -QUIT $MPID
        [[ $? -eq 0 ]] && rm -f $LOCKFILE
    else
        echo "Nginx server is not running!"
    fi
}
                                                   
reload() {
    echo "Reloading Nginx......"
    MPID=`ps aux | grep nginx | awk '/master/{print $2}'`
                                                      
    if [[ "${MPID}X" != "X" ]]; then
        kill -HUP $MPID
    else
        echo "Nginx can't reload!"
    fi
}
                                                   
case "$1" in
start)
    start
    ;;
                                                      
stop)
    stop
    ;;
                                                      
reload)
    reload
    ;;
                                                      
restart)
    stop
    sleep 1
    start
    ;;
                                                      
*)
    echo "Usage: $SCRIPTNAME {start|stop|reload|restart}"
    exit 3
    ;;
esac
                                                   
exit 0

                4 設置開機啟動

              chmod 755 /etc/init.d/nginx
              chkconfig --add nginx
              chkconfig  nginx on
              /etc/init.d/nginx start  

                5 測試

                     用瀏覽器訪問實際的域名 看看是否正常

                     重啟服務器 看nginx 是否隨機啟動

                6 配置相關

                        

######## 查看nginx狀態配置
location =/nginx_status {
        stub_status on;
        access_log off;
        #allow 127.0.0.1;
        #deny all;
 }

active connections – 活躍的連接數量
server accepts handled requests — 總共處理了11989個連接 , 成功創建11989次握手, 總共處理了11991個請求
reading — 讀取客戶端的連接數.
writing — 響應數據到客戶端的數量
waiting — 開啟 keep-alive 的情況下,這個值等於 active – (reading+writing), 意思就是 Nginx 已經處理完正在等候下一次請求指令的駐留連接.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM