基于域名的虚拟主机 : 不同的域名 相同的IP
基于端口的虚拟主机 : 不使用域名、IP来区分不同站点的内容,而是用不同的TCP端口号
基于IP地址的虚拟主机 : 不同的域名 不同的IP ( 需要加网络接口 ,应用的不广泛)
由于基于IP地址的虚拟主机需要添加网络接口 使用不广泛,所以下面只对基于域名的虚拟主机和基于端口的虚拟主机进行操作介绍
一丶Nginx基于端口的虚拟主机
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# mkdir -pv /usr/share/nginx/html/hya
[root@localhost ~]# echo "welcome to hya" > /usr/share/nginx/html/hya/index.html
[root@localhost ~]# vim /etc/nginx/nginx.conf
server {
listen 8080;
server_name www.hya.com;
location / {
root /usr/share/nginx/html/hya;
index index.html index.htm;
}
}
[root@localhost nginx]# systemctl restart nginx
[root@localhost nginx]# curl 192.168.253.130:8080
welcome to hya
二、Nginx基于域名的虚拟主机(基于以上配置操作)
配置如上一样