1.nginx虚拟机配置
nginx可以实现虚拟主机的配置,nginx支持三种类型的虚拟主机配置。
1、基于域名的虚拟主机 (server_name来区分虚拟主机——应用:外部网站)
2、基于ip的虚拟主机, (一块主机绑定多个ip地址)
3、基于端口的虚拟主机 (端口来区分虚拟主机——应用:公司内部网站,外部网站的管理后台)
基于域名的虚拟主机
为域名web.he.com创建index文件
mkdir -p /hello/html
vim /hello/html/index.html
为域名web.he.com配置路由映射
在/etc/hosts文件中添加
127.0.0.1 web.he.com
配置通过域名区分的虚拟机
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 80;
server_name he.com;
location / {
root /hello/html;
index index.html index.htm;
}
}
重新加载配置文件
nginx -