基于域名的虚拟主机(最常用)

最有用的虚拟主机配置方式。

一个域名只能绑定一个ip地址,一个ip地址可以被多个域名绑定。

 

测试:可以修改host文件实现域名访问。

修改hosts工具推荐:SwitchHosts!

  下载地址:https://github.com/oldj/SwitchHosts/releases

 

Centos中的nginx.conf配置如下:

 1     #一个Server就是一个虚拟主机
 2     server {
 3         listen       80;
 4         server_name  192.168.83.133;
 5 
 6         #charset koi8-r;
 7 
 8         #access_log  logs/host.access.log  main;
 9 
10         location / {
11             #root   html-133;
12         root  /home/ftpuser/www;#定义服务器的默认网站根目录位置
13             index  index.html index.htm;
14         }
15 
16     }
17 
18     server {
19         listen       80;
20         server_name  192.168.83.132;
21 
22         #charset koi8-r;
23 
24         #access_log  logs/host.access.log  main;
25 
26         location / {
27             root   html-132;
28             index  index.html index.htm;
29         }
30 
31     }
32 
33     server {
34         listen       80;
35         server_name  www.aaa.com;
36 
37         #charset koi8-r;
38 
39         #access_log  logs/host.access.log  main;
40 
41         location / {
42             root   html-133;
43             index  index.html index.htm;
44         }
45 
46     }
47 
48     server {
49         listen       80;
50         server_name  www.bbb.com;
51 
52         #charset koi8-r;
53 
54         #access_log  logs/host.access.log  main;
55 
56         location / {
57             root   html-132;
58             index  index.html index.htm;
59         }
60 
61     }

注意:ip地址和域名必须有

Windows的host配置:

浏览器访问:

 

posted @ 2019-03-01 12:33  清晨的第一抹阳光  阅读(251)  评论(0编辑  收藏  举报