一、配置
首先修改配置文件
#vi /usr/local/nginx/conf/nginx.conf
在最后一个结束符号}前加一行配置:
include vhost/*.conf;
意思就是/usr/local/nginx/conf/host下面的所有以.conf结尾的文件都会被加载
#mkdir /usr/local/nginx/conf/vhost
#cd /usr/local/nginx/conf/vhost
#vim default.conf
写入
server
{
listen 80 default_server;
server_name aaa.com;
index index.html index.htm index.php;
root /data/nginx/default;
}
#/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#/usr/local/nginx/sbin/nginx -s reload
mkdir -p /data/nginx/default
#echo "default_server" > /data/nginx/default/index.html
//创建索引页
二、检验测试
#curl -x127.0.0.1:80 aaa.com
//访问aaa.com
default_server
#curl -x127.0.0.1:80 1212.com
//访问一个没有定义过的域名,也会访问aaa.com
default_server
检验成功