基于域名的虚拟主机 : 不同的域名 相同的IP
基于端口的虚拟主机 : 不使用域名、IP来区分,而是用不同的TCP端口号
基于IP地址的虚拟主机 : 不同的域名 不同的IP ( 需要加网络接口 )
安装nginx (这里是yum装)
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install nginx
创建个测试页面
[root@localhost ~]# vim /usr/share/nginx/html/index.html
小红花
~
修改配置文件 (基于端口)
[root@localhost ~]# vim /etc/nginx/nginx.conf
server {
listen 8080; #端口
location / {
root /usr/share/nginx/html;
index index.html;
}
}
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# curl 192.168.27.137:8080
小红花
修改配置文件 (基于域名)
[root@localhost ~]# vim /etc/nginx/nginx.conf
server {
listen 80;
location / {
server_name www.hong.com; #域名
root /usr/share/nginx/html;
index index.html;
}
}
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# vim /etc/hosts ##添加域名解析
192.168.27.137 www.hong.com
[root@localhost ~]# curl www.hong.com
小红花