Java学习笔记紫水晶书院•文思飞扬(散文、随笔、杂文、评论、科普、日记……IT@程序员猿媛

通过域名区分不同的虚拟主机

2019-07-30  本文已影响5人  您好简书

1.1.1. 什么是域名

域名就是网站。

www.baidu.com

www.taobao.com

www.jd.com

Tcp/ip

Dns服务器:把域名解析为ip地址。保存的就是域名和ip的映射关系。

一级域名:

Baidu.com

Taobao.com

Jd.com

二级域名:

www.baidu.com

Image.baidu.com

Item.baidu.com

三级域名:

1.Image.baidu.com

Aaa.image.baidu.com

DNS服务器是专门解析域名的


image.png

一个域名对应一个ip地址,一个ip地址可以被多个域名绑定。

本地测试可以修改hosts文件。
修改window的hosts文件:(C:\Windows\System32\drivers\etc)
可以配置域名和ip的映射关系,如果hosts文件中配置了域名和ip的对应关系,不需要走dns服务器。



# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

#0.0.0.0 statsfe2.update.microsoft.com.akadns.net
#0.0.0.0 fe2.update.microsoft.com.akadns.net
#0.0.0.0 s0.2mdn.net
#0.0.0.0 survey.watson.microsoft.com
#0.0.0.0 view.atdmt.com
#0.0.0.0 watson.microsoft.com
#0.0.0.0 watson.ppe.telemetry.microsoft.com
#0.0.0.0 vortex.data.microsoft.com
#0.0.0.0 vortex-win.data.microsoft.com
#0.0.0.0 telecommand.telemetry.microsoft.com
#0.0.0.0 telecommand.telemetry.microsoft.com.nsatc.net
#0.0.0.0 oca.telemetry.microsoft.com
#0.0.0.0 sqm.telemetry.microsoft.com
#0.0.0.0 sqm.telemetry.microsoft.com.nsatc.net
#0.0.0.0 watson.telemetry.microsoft.com
#0.0.0.0 watson.telemetry.microsoft.com.nsatc.net
#0.0.0.0 redir.metaservices.microsoft.com
#0.0.0.0 choice.microsoft.com
#0.0.0.0 choice.microsoft.com.nsatc.net
#0.0.0.0 wes.df.telemetry.microsoft.com
#0.0.0.0 services.wes.df.telemetry.microsoft.com
#0.0.0.0 sqm.df.telemetry.microsoft.com
#0.0.0.0 telemetry.microsoft.com
#0.0.0.0 telemetry.appex.bing.net
#0.0.0.0 telemetry.urs.microsoft.com
#0.0.0.0 settings-sandbox.data.microsoft.com
#0.0.0.0 watson.live.com
#0.0.0.0 statsfe2.ws.microsoft.com
#0.0.0.0 corpext.msitadfs.glbdns2.microsoft.com
#0.0.0.0 compatexchange.cloudapp.net
#0.0.0.0 a-0001.a-msedge.net
#0.0.0.0 sls.update.microsoft.com.akadns.net
#0.0.0.0 diagnostics.support.microsoft.com
#0.0.0.0 corp.sts.microsoft.com
#0.0.0.0 statsfe1.ws.microsoft.com
#0.0.0.0 feedback.windows.com
#0.0.0.0 feedback.microsoft-hohm.com
#0.0.0.0 feedback.search.microsoft.com
#0.0.0.0 rad.msn.com
#0.0.0.0 preview.msn.com
#0.0.0.0 ad.doubleclick.net
#0.0.0.0 ads.msn.com
#0.0.0.0 ads1.msads.net
#0.0.0.0 ads1.msn.com
#0.0.0.0 a.ads1.msn.com
#0.0.0.0 a.ads2.msn.com
#0.0.0.0 adnexus.net
#0.0.0.0 adnxs.com
#0.0.0.0 az361816.vo.msecnd.net
#0.0.0.0 az512334.vo.msecnd.net
#0.0.0.0 ssw.live.com
#0.0.0.0 ca.telemetry.microsoft.com
#0.0.0.0 i1.services.social.microsoft.com
#0.0.0.0 i1.services.social.microsoft.com.nsatc.net
#0.0.0.0 df.telemetry.microsoft.com
#0.0.0.0 reports.wes.df.telemetry.microsoft.com
#0.0.0.0 cs1.wpc.v0cdn.net
#0.0.0.0 vortex-sandbox.data.microsoft.com
#0.0.0.0 oca.telemetry.microsoft.com.nsatc.net
#0.0.0.0 pre.footprintpredict.com
#0.0.0.0 spynet2.microsoft.com
#0.0.0.0 spynetalt.microsoft.com
#0.0.0.0 fe3.delivery.dsp.mp.microsoft.com.nsatc.net
#0.0.0.0 cache.datamart.windows.com
#0.0.0.0 db3wns2011111.wns.windows.com
#0.0.0.0 settings-win.data.microsoft.com
#0.0.0.0 v10.vortex-win.data.microsoft.com
#0.0.0.0 win10.ipv6.microsoft.com
#0.0.0.0 ca.telemetry.microsoft.com
#0.0.0.0 i1.services.social.microsoft.com.nsatc.net

#127.0.0.1 wa.kuwo.cn
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com

#tudou
#127.0.0.1 adextensioncontrol.tudou.com
#127.0.0.1 iwstat.tudou.com
#127.0.0.1 nstat.tudou.com
#127.0.0.1 stats.tudou.com
#127.0.0.1 *.p2v.tudou.com*
#127.0.0.1 at-img1.tdimg.com
#127.0.0.1 at-img2.tdimg.com
#127.0.0.1 at-img3.tdimg.com
#127.0.0.1 adplay.tudou.com
#127.0.0.1 adcontrol.tudou.com
#127.0.0.1 stat.tudou.com
#127.0.0.1 walp.atm.youku.com
#ku6
#127.0.0.1 1.allyes.com.cn
#127.0.0.1 analytics.ku6.com
#127.0.0.1 gug.ku6cdn.com
#127.0.0.1 ku6.allyes.com
#127.0.0.1 ku6afp.allyes.com
#127.0.0.1 pq.stat.ku6.com
#127.0.0.1 st.vq.ku6.cn
#127.0.0.1 stat0.888.ku6.com
#127.0.0.1 stat1.888.ku6.com
#127.0.0.1 stat2.888.ku6.com
#127.0.0.1 stat3.888.ku6.com
#127.0.0.1 static.ku6.com
#127.0.0.1 v0.stat.ku6.com
#127.0.0.1 v1.stat.ku6.com
#127.0.0.1 v2.stat.ku6.com
#127.0.0.1 v3.stat.ku6.com
#qiyi
#127.0.0.1 afp.qiyi.com
#127.0.0.1 focusbaiduafp.allyes.com
#sina
#127.0.0.1 dcads.sina.com.cn
#pptv
#127.0.0.1 wafp.pptv.com
#127.0.0.1 jp.as.pptv.com
#127.0.0.1 de.as.pptv.com
#127.0.0.1 as.aplus.pptv.com
#127.0.0.1 static.g.pptv.com
#127.0.0.1 vas.aplus.pptv.com
#127.0.0.1 tips.passport.pptv.com
#127.0.0.1 static.qipao.pptv.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com
#127.0.0.1 l.qq.com
#127.0.0.1 ra.gtimg.com
#127.0.0.1 livec.l.qq.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com
#127.0.0.1 atm.youku.com
#127.0.0.1 vid.atm.youku.com
#127.0.0.1 Fvid.atm.youku.com
#127.0.0.1 walp.atm.youku.com
#127.0.0.1 html.atm.youku.com
#127.0.0.1 valb.atm.youku.com
#127.0.0.1 valf.atm.youku.com
#127.0.0.1 valo.atm.youku.com
#127.0.0.1 valp.atm.youku.com
#127.0.0.1 lstat.youku.com
#127.0.0.1 speed.lstat.youku.com
#127.0.0.1 urchin.lstat.youku.com
#127.0.0.1 stat.youku.com
#127.0.0.1 static.lstat.youku.com
#127.0.0.1 valc.atm.youku.com

#-------′?′|?á±?ìú??êó?μ1???-------

还有一个好用的工具SwitchHosts!.exe

image.png

本地的IP绑定域名设置


image.png

新建一个camel

image.png

绑定完ip和域名的对应关系之后

下一步 我们要在虚拟主机完成
cd /usr/local/nginx

找到-rw-r--r--. 1 root root 2656 7月 28 01:39 nginx.conf
添加server 配置相同的端口 ,但是server_name 为绑定的域名

    server {
        listen       80;
        server_name  wwww.camel.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html-test1;
            index  index.html index.htm;
        }
}
    server {
        listen       80;
        server_name  wwww.camel1.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html-test;
            index  index.html index.htm;
        }
}

第一步 cd /usr/local/nginx/ 复制html

[root@Nigux nginx]# cp -r html html-test
[root@Nigux nginx]# cp -r html html-test1

区分两个不同的界面


drwxr-xr-x. 2 root root 4096 7月  29 23:06 conf
drwxr-xr-x. 2 root root   40 7月  28 01:39 html
drwxr-xr-x. 2 root root   40 7月  29 22:54 html81
drwxr-xr-x. 2 root root   40 7月  30 00:09 html-test
drwxr-xr-x. 2 root root   40 7月  30 00:09 html-test1
drwxr-xr-x. 2 root root   19 7月  28 01:39 sbin
[root@Nigux nginx]# vim html-test/index.html
[root@Nigux nginx]# vim html-test1/index.html

修改页面之后,shift+zz 保存退出后,重启一下服务

[root@Nigux nginx]# sbin/nginx -s reload

测试:

http://192.168.191.129:81/

image.png

http://192.168.191.129/

image.png
上一篇 下一篇

猜你喜欢

热点阅读