V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
DreamCMS
V2EX  ›  NGINX

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

  •  
  •   DreamCMS · 2021-10-12 10:14:40 +08:00 · 1805 次点击
    这是一个创建于 898 天前的主题,其中的信息可能已经有所发展或是发生改变。
    譬如源地址是 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 上的资源)
    10 条回复    2021-10-13 16:09:45 +08:00
    InDom
        1
    InDom  
       2021-10-12 10:16:21 +08:00   ❤️ 1
    我的理解是反代+缓存。
    zenwong
        2
    zenwong  
       2021-10-12 10:24:25 +08:00   ❤️ 1
    OpenResty
    pupboss
        3
    pupboss  
       2021-10-12 10:24:25 +08:00   ❤️ 1
    cpstar
        4
    cpstar  
       2021-10-12 10:29:45 +08:00   ❤️ 1
    缓存能解决一时,但我觉得 LZ 是要做镜像站
    Xusually
        5
    Xusually  
       2021-10-12 10:31:10 +08:00   ❤️ 1
    在 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
        6
    DreamCMS  
    OP
       2021-10-12 11:14:47 +08:00
    @cpstar 是的主站要关了,我想备份一下。
    Dagundelv
        7
    Dagundelv  
       2021-10-12 11:23:19 +08:00
    wget
    zyq2280539
        8
    zyq2280539  
       2021-10-12 12:42:45 +08:00
    rsync 设置好固定的文件夹+crontab 定时同步就好了
    dier
        9
    dier  
       2021-10-12 13:53:02 +08:00   ❤️ 1
    ```
    wget --mirror --convert-links www.a.com
    ```
    huangzxx
        10
    huangzxx  
       2021-10-13 16:09:45 +08:00   ❤️ 1
    楼主的需求是镜像站吧,以下供参考:
    1 、用 rsync a 同步到 b
    2 、b 上的 nginx 配置,如果文件 b 不存在,则反代到 a 。

    location / {
    try_files $uri @fallback;
    }

    location @fallback {
    proxy_pass https://a.com;
    include proxy.conf;
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1548 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:12 · PVG 01:12 · LAX 10:12 · JFK 13:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.