正文
实现三种虚拟主机需要修改nginx的nginx.conf文件内http\server下的代码,下面分享两种配置虚拟主机的方法:
# 基于域名的虚拟主机
server {
listen 80; # 监听端口
server_name a.com; # 监听域名,注意localhost也是一个域名,可在/etc/hosts中修改
location / {
root /var/www/a.com; # 根目录定位
index index.html; # 默认访问页面定位
}
}
# 基于端口的虚拟主机配置
server {
listen 8080; # 监听端口
server_name 192.168.1.204; # 监听ip或域名
location / {
root /var/www/html8080; # 根目录定位
index index.html; # 默认访问页面定位
}
}