修改/usr/local/nginx/conf/nginx.conf 文件,添加虚拟主机,修改完文件后,重启nginx
在/usr/local/nginx下创建一个aaa_html文件夹,此目录为aaa.test.com域名的访问目录,并将aaa_html目录中的index.html内容改为"Welcome to aaa nginx!"
配置虚拟主机
修改/usr/local/nginx/conf/nginx.conf 文件,配置 aaa.test.com 虚拟主机
server {
# 监听ip和端口
listen 172.16.232.4:80;
#虚拟主机的名称
server_name aaa.test.com;
#所有的请求都以/开始,所有的请求都可以匹配此location
location / {
虚拟主机存放网页的根目录
root /usr/local/nginx/aaa_html;
# 欢迎页面
index index.html index.htm;
}
}
虚拟主机配置成功,然后重启启动nginx,使配置生效
./nginx -s quit
./nginx -t
./nginx