nginx配置虛擬主機

什麼是虛擬主機:

應用軟硬件技術,把一臺主機分成一臺臺虛擬主機,每臺主機都有獨立的網站,域名

Nginx虛擬主機類型:

  1. 基於IP

  2. 基於域名

  3. 基於端口

    eth0添加兩個IP別名

ifconfig eth0:1 192.168.22.11 broadcast192.168.22.255 netmask 255.255.255.0

route add –host 192.168.22.11 dev eth0:1

ifconfig eth0:2 192.168.22.12 broadcast192.168.22.255 netmask 255.255.255.0

route add –host 192.168.22.12 dev eth0:2

:ifconfig

        此命令可以手動啓動,觀察,和設置網絡接口的相關的參數。

        格式:ifconfig interface [options]

                     interface:指的是網絡接口,如:eth0eth1ppp0等;

                     options可以設置的參數:

                          up|down:可以啓用或關閉網絡接口

                          netmask:子網掩碼

                          broadcast:廣播地址

                          mtu:最大傳輸單元(Byte

         注:ifconfig eth00 [ip] 指的是在網絡接口上再設置一個仿真的網絡接口。

route

         1.#route [-nee]

            此命令用於查詢路由的信息

            -n不使用通信協議或主機名稱,直接用ipport number顯示路由信息                 

            (此種方式顯示路由信息比較快)

            -ee   使用更詳細的信息來顯示。

         2.#route add|del [-net|-host] [網段或主機] netmask [mask] [gw|dev]

            增加或刪除路由的相關參數

            netmask,與網段有關,設置netmask值可以決定網段的大小

            gwgateway的縮寫

            dev指定網卡聯機,後接eth0等。

將上兩句添加到/etc/rc.local開機運行.

修改nginx配置文件nginx.conf一般在/etc/nginx/nginx.conf

  • 基於IP

server {

    #監聽的IP端口

listen       192.168.22.11:80;

#主機名稱

     server_name 192.168.22.11;

      #charset koi8-r;

         #訪問日誌文件存放路徑

     #access_log logs/server1.access.log  main;

    location / {

        #網頁文件存放的目錄

root   /usr/share/nginx/html/server1;

                   #默認首頁文件,順序從左到右

       index  index.html index.htmindex.php;

        }

        error_page  404              /404.html;

    location = /404.html {

        root   /usr/share/nginx/html;

}

其它虛擬主機依此配置,每個server{……..}代表一個虛擬主機

  • 基於域名

server {

    #監聽的IP端口

listen       80;

#主機名稱

    server_name  www.xxoo.com xxoo.com *.xxoo.com;

      #charset koi8-r;

         #訪問日誌文件存放路徑

     #access_log  logs/xxoo.access.log  main;

    location / {

        #網頁文件存放的目錄

root   /usr/share/nginx/html/server1;

                   #默認首頁文件,順序從左到右

       index  index.html index.htmindex.php;

        }

        error_page  404              /404.html;

    location = /404.html {

        root   /usr/share/nginx/html;

}


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