您好,登錄后才能下訂單哦!
nginx支持的虛擬主機有三種
1、基于域名的虛擬主機
2、基于IP的虛擬主機
3、基于端口的虛擬主機
一、基于域名構建
1、編譯安裝nginx服務
2、配置DNS域名解析服務
3、配置虛擬主機
a、創建自測網頁
[root@localhost?named]#?cd? [root@localhost?~]#?mkdir?-p?/var/www/html/kgc [root@localhost?~]#?mkdir?-p?/var/www/html/accp [root@localhost?~]#?ls?/var/www/html/accp??kgc [root@localhost?~]#?cd?/var/www/html/ [root@localhost?html]#?echo?"this?kgc?web"?>?kgc/index.html [root@localhost?html]#?echo?"this?accp?web"?>?accp/index.html
b、編輯nginx.conf配置文件
vim?/usr/local/nginx/conf/nginx.conf ????include?conf.d/*.conf; ????server?{ ????????listen?????????????80; ????????server_name??www.kgc.com; ????????charset?utf-8; ????????access_log??logs/www.kgc.com.access.log??; ????????location?/?{ ????????????root???/var/www/html/kgc; ????????????index??index.html?index.htm; ????????} ????????error_page???500?502?503?504??/50x.html; ????????location?=?/50x.html?{ ????????????root???html; ????????} ????} ????server?{ ????????listen?????????????80; ????????server_name??www.accp.com; ????????charset?utf-8; ????????access_log??logs/www.accp.com.access.log??; ????????location?/?{ ????????????root???/var/www/html/accp; ????????????index??index.html?index.htm; ????????} ????????error_page???500?502?503?504??/50x.html; ????????location?=?/50x.html?{ ????????????root???html; ????????} ????}
c、重載服務
systemctl?restart?nginx netstat?-ntap?|?grep?80
d、訪問測試
www.kgc.com www.accp.com
二、基于端口
a、創建另一個端口的測試網頁
[root@localhost?~]#?cd?/var/www/html/ [root@localhost?html]#?echo?"this?is?kgc?8080?web"?>?kgc/index.html
b、編輯nginx.conf配置文件,僅修改監聽地址
????server?{ ????????listen?????????????192.168.109.137:80; ????????server_name??www.accp.com; ????????charset?utf-8; ????????access_log??logs/www.accp.com.access.log??; ????????location?/?{ ????????????root???/var/www/html/accp; ????????????index??index.html?index.htm; ????????} ????????error_page???500?502?503?504??/50x.html; ????????location?=?/50x.html?{ ????????????root???html; ????????} ????} ????server?{ ????????listen?????????????192.168.109.137:8080; ????????server_name??www.accp.com; ????????charset?utf-8; ????????access_log??logs/www.accp8080.com.access.log??; ????????location?/?{ ????????????root???/var/www/html/accp8080; ????????????index??index.html?index.htm; ????????} ????????error_page???500?502?503?504??/50x.html; ????????location?=?/50x.html?{ ????????????root???html; ????????} ????}
c、重載nginx服務
systemctl?restart?nginx netstat?-ntap?|?grep?80
d、測試網頁
www.accp.com www.accp.com8080
三、基于IP
1、修改網頁配置文件中的區域數據配置文件
vim?/var/named/kgc.com.zone systemctl?restart?named
2、編輯nginx.conf中的配置,修改ip地址
?server?{ ????????listen?????????????192.168.109.137:80; ????????server_name??www.kgc.com; ????????charset?utf-8; ????????access_log??logs/www.kgc.com.access.log??; ????????location?/?{ ????????????root???/var/www/html/kgc; ????????????index??index.html?index.htm; ????????} ????????error_page???500?502?503?504??/50x.html; ????????location?=?/50x.html?{ ????????????root???html; ????????} ????} ????server?{ ????????listen?????????????192.168.109.134:80; ????????server_name??www.accp.com; ????????charset?utf-8; ????????access_log??logs/www.accp.com.access.log??; ????????location?/?{ ????????????root???/var/www/html/accp; ????????????index??index.html?index.htm; ????????} ????????error_page???500?502?503?504??/50x.html; ????????location?=?/50x.html?{ ????????????root???html; ????????} ????}
c、重載nginx服務
systemctl?restart?nginx netstat?-ntap?|?grep?80
d、測試網頁
192.168.109.137 192.168.109.134
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。