如何利用 nginx 备份源地址网站文件到 B 服务器上存储?

2021-10-12 10:14:40 +08:00
 DreamCMS
譬如源地址是 a.com ,B 地址是 b.com
现在 a.com 存在哟个 a.com/1.txt 文件,1.html 里面包油一个 css 目录下的 1.css 的 a.com/1.html a.com/css/1.css

现在部署了 nginx 的 b 服务器上我只需访问 b.com/1.txt b.com/1.html (本身不存在的,去读取了 a.com 上的)自动存储下来对应的 1.txt. 1.html css/1.css (如果存在文件即不再读取 a.com 上的资源)
1851 次点击
所在节点    NGINX
10 条回复
InDom
2021-10-12 10:16:21 +08:00
我的理解是反代+缓存。
zenwong
2021-10-12 10:24:25 +08:00
OpenResty
pupboss
2021-10-12 10:24:25 +08:00
cpstar
2021-10-12 10:29:45 +08:00
缓存能解决一时,但我觉得 LZ 是要做镜像站
Xusually
2021-10-12 10:31:10 +08:00
在 http 段开启缓存,在 server 段配置反向代理:
示例:

http {
# ...
proxy_cache_path /data/nginx/cache keys_zone=one:10m;

server {
listen 80;
server_name b.com;

proxy_cache mycache;
location / {
proxy_pass http://a.com:80;
}
}
}
DreamCMS
2021-10-12 11:14:47 +08:00
@cpstar 是的主站要关了,我想备份一下。
Dagundelv
2021-10-12 11:23:19 +08:00
wget
zyq2280539
2021-10-12 12:42:45 +08:00
rsync 设置好固定的文件夹+crontab 定时同步就好了
dier
2021-10-12 13:53:02 +08:00
```
wget --mirror --convert-links www.a.com
```
huangzxx
2021-10-13 16:09:45 +08:00
楼主的需求是镜像站吧,以下供参考:
1 、用 rsync a 同步到 b
2 、b 上的 nginx 配置,如果文件 b 不存在,则反代到 a 。

location / {
try_files $uri @fallback;
}

location @fallback {
proxy_pass https://a.com;
include proxy.conf;
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/807224

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX