Linux10.3 Nginx默认虚拟主机

Posted Learning Notes

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux10.3 Nginx默认虚拟主机相关的知识,希望对你有一定的参考价值。

  编辑nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

  删除server{}主机配置端,在最后增加

include vhost/*.conf
mkdir /usr/local/nginx/conf/vhost

  在vhost文件夹内,创建默认主机配置文件aaa.com.conf文件,编辑如下:

server
{
    listen 80 default_server;  // 有这个标记的就是默认虚拟主机
    server_name aaa.com;
    index index.html index.htm index.php;
    root /data/wwwroot/default;       //网站目录,不存在需要创建
}

  在网站目录创建html文件

echo “This is a default site.”>/data/wwwroot/default/index.html

  检查nginx配置文件语法,及重新加载配置文件

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload

  测试,默认虚拟主机,不管什么域名,都会指向这个站点

[[email protected] default]# curl localhost
echo “This is a default site.”
[[email protected] default]# curl -x127.0.0.1:80 123.com
echo “This is a default site.”
[[email protected] default]# curl -x127.0.0.1:80 aaa.com
echo “This is a default site.”
[[email protected] default]# curl -x127.0.0.1:80 www.baidu.com
echo “This is a default site.”

  

以上是关于Linux10.3 Nginx默认虚拟主机的主要内容,如果未能解决你的问题,请参考以下文章