1,基于域名的虚拟主机
2,基于IP的虚拟主机
3,基于端口的虚拟主机
一、基于域名构建
1,编译安装nginx服务
2,配置DNS域名解析服务
3,配置虚拟主机
,创建自测网页
(root@localhost命名)# cd # mkdir - p/var/www/html/kgc root@localhost ~ # mkdir - p/var/www/html/accp root@localhost ~ (root@localhost ~) # ls/var/www/html/accp kgc # cd/var/www/html/root@localhost ~ [html] root@localhost #回声“这kgc web”比;kgc/index . html [html] root@localhost #回声“这accp网络”在accp/index . html
b,编辑nginx。参看配置文件
vim/usr/local/nginx/conf/nginx.conf 包括conf.d/* . conf; 服务器{ 听80; server_name www.kgc.com; utf - 8字符集; access_log日志/www.kgc.com.access.log; 位置/{ 根/var/www/html/kgc; 指数指数。html你; } error_page 500 502 503 504/50 x.html; 位置=/50 x。html { 根html; } } 服务器{ 听80; server_name www.accp.com; utf - 8字符集; access_log日志/www.accp.com.access.log; 位置/{ 根/var/www/html/accp; 指数指数。html你; } error_page 500 502 503 504/50 x.html; 位置=/50 x。html { 根html; } }
c,重载服务
systemctl重启nginx netstat -ntap | grep 80
d,访问测试
www.kgc.com www.accp.com
二,基于端口
,创建另一个端口的测试网页
root@localhost ~ # cd/var/www/html/(root@localhost html) #回声”这是kgc 8080网络”在kgc/index . html
b,编辑nginx。参看配置文件,仅修改监听地址
服务器{ 听192.168.109.137:80; server_name www.accp.com; utf - 8字符集; access_log日志/www.accp.com.access.log; 位置/{ 根/var/www/html/accp; 指数指数。html你; } error_page 500 502 503 504/50 x.html; 位置=/50 x。html { 根html; } } 服务器{ 听192.168.109.137:8080; server_name www.accp.com; utf - 8字符集; access_log日志/www.accp8080.com.access.log; 位置/{ 根/var/www/html/accp8080; 指数指数。html你; } error_page 500 502 503 504/50 x.html; 位置=/50 x。html { 根html; } }
c,重载nginx服务
systemctl重启nginx netstat -ntap | grep 80
d,测试网页
www.accp.com www.accp.com8080
三,基于IP
1,修改网页配置文件中的区域数据配置文件
vim/var/named/kgc.com.zone systemctl重新命名为
2,编辑nginx。设计中的配置,修改ip地址
服务器{ 听192.168.109.137:80; server_name www.kgc.com; utf - 8字符集; access_log日志/www.kgc.com.access.log; 位置/{ 根/var/www/html/kgc; 指数指数。html你; } error_page 500 502 503 504/50 x.html; 位置=/50 x。html { 根html; } } 服务器{ 听192.168.109.134:80; server_name www.accp.com; utf - 8字符集; access_log日志/www.accp.com.access.log; 位置/{ 根/var/www/html/accp; 指数指数。html你; } error_page 500 502 503 504/50 x.html; 位置=/50 x。html { 根html; } }
c,重载nginx服务
systemctl重启nginx netstat -ntap | grep 80
d,测试网页
192.168.109.137 192.168.109.134