nginx支持的虛擬主機有三種html
一、基於域名的虛擬主機nginx
二、基於IP的虛擬主機web
三、基於端口的虛擬主機vim
1、基於域名構建bash
一、編譯安裝nginx服務ide
二、配置DNS域名解析服務測試
三、配置虛擬主機this
a、建立自測網頁spa
[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配置文件rest
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
2、基於端口
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
3、基於IP
一、修改網頁配置文件中的區域數據配置文件
vim /var/named/kgc.com.zone systemctl restart named
二、編輯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