首页 > 其他 > 详细

Nginx默认虚拟主机

时间:2021-09-07 05:29:32      阅读:33      评论:0      收藏:0      [点我收藏+]

Nginx默认虚拟主机

配置默认虚拟主机

定义一个默认虚拟主机有两种方法

1、放到一个目录里,根据名称来设置

2、在配置文件里设置default_server

[root@antong vhost]# echo "this is a default site." >> /data/nginx/default/index.html[root@antong nginx]# vim conf/nginx.conf  //将server内容部分删掉,末尾加入include vhost/*.conf;
···
application/xml;
include vhost/*.conf;
}
[root@antong nginx]# cd conf/
[root@antong conf]# mkdir vhost
[root@antong conf]# cd vhost/
[root@antong vhost]# vim aaa.com.conf
{
    listen 80 default_server;  // 有这个标记的就是默认虚拟主机
    server_name aaa.com;
    index index.html index.htm index.php;
    root /data/nginx/default;
}
[root@antong vhost]# mkdir -p /data/nginx/default
[root@antong vhost]# echo "this is a default site." >> /data/nginx/default/index.html
[root@antong vhost]# /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
[root@antong vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@antong vhost]# curl localhost
this is a default site.

因为定义了默认虚拟主机,所以只要访问ip,不管域名是什么都会跳转到默认的虚拟主机

[root@antong vhost]# curl -x127.0.0.1:80 bbb.com
this is a default site.
[root@antong vhost]# curl -x127.0.0.1:80 aaa.com   
this is a default site.

Nginx默认虚拟主机

原文:https://www.cnblogs.com/antong/p/15233056.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!