nginx 編譯安裝

一、安裝依賴包

yum -y install pcre-devel zlib-devel

useradd -M -s /sbin/nologin nginx          //新建nginx用戶,並不指定宿主目錄

tar xzvf /media/nginx-1.2.8.tar.gz -C /opt    //解壓源碼包

二、編譯安裝

cd /opt/nginx-1.2.8/

./configure \

--prefix=/usr/local/nginx \     //指定nginx安裝目錄

--user=nginx --group=nginx \

--with-http_stub_status_module

make

make install

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/   //建立軟連接

三、製作管理腳本

vi /etc/init.d/nginx

#!/bin/bash

# chkconfig: 35 99 20

# description: Nginx Service Control Script

PROG="/usr/local/nginx/sbin/nginx"

PIDF="/usr/local/nginx/logs/nginx.pid"

case "$1" in

  start)

    $PROG

    ;;

  stop)

    kill -s QUIT $(cat $PIDF)

    ;;

  restart)

    $0 stop

    $0 start

    ;;

  reload)

    kill -s HUP $(cat $PIDF)

    ;;

  *)

        echo "Usage: $0 {start|stop|restart|reload}"

        exit 1

esac

exit 0

chmod +x /etc/init.d/nginx   //增加執行權限

chkconfig --add nginx        //nginx服務加入到service管理

用以下命令管理nginx的啓動

nginx -t//檢查

nginx//啓動

killall -1 nginx//重啓

killall -3 nginx//停止

四、配置統計頁面

cd /usr/local/nginx/conf     //切換到主配置文件目錄

cp nginx.conf nginx.conf.back     //備份主配置文件,以防萬一嘛!

grep -v "#" nginx.conf > 123

mv -f 123 nginx.conf

vi /usr/local/nginx/conf/nginx.conf               //修改主配置文件

 

server {

        listen       80;

        server_name  localhost;

charset utf-8;

 

        location / {

            root   html;

            index  index.html index.htm;

        }

插入下面四行

        location ~ /status {//訪問位置爲/status

        stub_status   on;//打開狀態統計功能

        access_log off;//關閉此位置的日誌記錄

        }

 

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

}

 

在遊覽器輸入192.168.1.10即可訪問nginx的默認首頁,加/status即可訪問統計頁面

wKioL1NJO0zSU1frAABfwdyUFgQ895.jpg

/usr/local/nginx/html/index.html   默認主頁路徑,配置虛擬主機,默認主頁依然會生效,而apache配置虛擬主機後,默認主頁不在生效

六、配置虛擬主機

server {

        server_name  www.benet.com;

        location / {

            root   /var/www/benet;

            index  index.html index.php;

        }

    }

    server {

        server_name  www.accp.com;

        location / {

            root   /var/www/accp;

            index  index.html index.php;

       }

}

在遊覽器輸入www.benet.comwww.accp.com即可訪問對應的網站

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章