Del*_*tik 24
听起来您正在运行本地 Web 服务器。优秀。
在 Mac 的文件系统中,有一个名为/etc/hosts
. 您可以fooCDN.com
通过在以下行中添加以下行将所有请求重定向到您的本地计算机/etc/hosts
:
127.0.0.1 foocdn.com www.foocdn.com
Run Code Online (Sandbox Code Playgroud)
您将需要 root(超级用户)权限来编辑/etc/hosts
.
上面的行意味着fooCDN.com
将从您自己的计算机加载,其中 Web 服务器正在侦听。
但是,您没有指定在本地运行的 Web 服务器。按照 Web 服务器的文档,您应该创建一个虚拟主机,将 的文档根目录fooCDN.com
指向/Users/name/Desktop/
。
这是一个示例配置(我自己没有测试过),您可以尝试与Apache一起使用:
<VirtualHost 127.0.0.1:80>
ServerName foocdn.com
ServerAlias www.foocdn.com
DocumentRoot /Users/name/Desktop
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
这是Nginx的示例配置(也未经测试):
server {
listen 80;
root /Users/name/Desktop;
server_name foocdn.com;
}
Run Code Online (Sandbox Code Playgroud)
不要忘记重新启动您的 Web 服务器服务或重新加载新的配置文件。
tec*_*rus 12
我把这个小代理服务器混在一起,只下载丢失的文件。只需将 /etc/hosts 文件设置为指向要缓存在 127.0.0.1 的站点和要在 0.0.0.0 阻止的站点
#!/bin/sh
nc -ll -p 80 -e sh -c '
while read A B DUMMY
do
case "$A" in
[Gg][Ee][Tt])
FULL=$B #full path of the file
F=${FULL##*/}
F=${F%%\?*} #file name only
#if we have it cat it back to browser
[ -f "$F" ] && cat "$F" && break
;;
[Hh][Oo][Ss][Tt]*)
[ -f "$F" ] && break #file already exists
HOST=${B:0:$((${#B}-1))} #the host name
#resolve by DNS first so we can cache it
sed -i "s/hosts:\t\tfiles /hosts:\t\t/g" /etc/nsswitch.conf
wget -t 0 -q --no-dns-cache $HOST$FULL
#got it now revert to checking host file 1st
sed -i "s/hosts:\t\t/hosts:\t\tfiles /g" /etc/nsswitch.conf
#cat the file because I didn't think to wget through tee
cat "$F"
break
;;
esac
done
'
Run Code Online (Sandbox Code Playgroud)
注意它把所有文件放在一个目录中,所以可能会导致版本冲突。(我是故意这样做的,所以我不会有 500 个 jquery 副本)
归档时间: |
|
查看次数: |
4536 次 |
最近记录: |