非windows系统如何本地搭建cdn

想通过 host 将 ajax.googleapis.com 映射到本地,这样许多国外的网站就可打开的快一些了,各路高手给个思路

在博客园看到了这篇文章,作者写的不错,但是本地是mac和linux,希望看过或者用过的朋友们给点思路。

阅读 4.1k
3 个回答

修改 %SystemRoot%\System32\drivers\etc\hosts 文件

通常是 C:\WINDOWS\System32\drivers\etc\hosts

# 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

127.0.0.1  ajax.googleapis.com

自己来答一下吧,我本地搭建了apache的服务,然后修改hosts将 ajax.googleapis.com 指向apache服务器,然后把对应的静态资源部署到apache上,当然效果也不是很理想,有些关于数据的请求还是很慢,大概3~5秒。

这么能起到一定的效果,希望以后能有更好的解决方案。

不用那么麻烦 直接把ajax.googleapis.com指向127.0.0.1, 通常不会影响网页显示。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进