nginx - nginx 的代理缓存超时/延迟?

标签 nginx proxy

为您提供一些有关我的问题的背景信息:

我有一个可以安装软件并公开提供服务的应用程序。安装时:

  1. 将基本文件安装到根路径(即 /var/www/{site})
  2. 创建一个新的 nginx 配置文件并将其放置在 /etc/nginx/sites-available/{site}
  3. /etc/nginx/sites-enabled/{site} 创建到该文件的符号链接(symbolic link)
  4. 重新加载 nginx 配置:service nginx reload
  5. 向 CloudFlare 发送 API 调用,将来自 {site}.mydomain.com 的所有请求定向到服务器的 IP 地址

之后,{site}.mydomain.com 应该可以工作,但...它不起作用!

...直到您等待大约 5 分钟,然后它就会神奇地开始工作。 nginx 代理生效之前是否有延迟?

如果我删除 {site} 并重新添加它(与上面的过程相同),即使它之前可以工作,它也会停止工作一段时间,然后再开始工作。

我无法解释发生了什么!

nginx 配置(其中 {site}foobar)

upstream mydomain_foobar {
    server 127.0.0.1:4567;
}

server {
    listen 80;

    server_name foobar.mydomain.com;
    root /var/www/mydomain/foobar/;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://mydomain-foobar/;
        proxy_redirect off;

        # Socket.io Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

最佳答案

在过去一个月反复查看这个问题后,发现这个问题与 nginx 根本无关。

rec_new API 调用发送到 CloudFlare 时,其记录大约需要五分钟(300 秒 TTL)才能更新。对于 CloudFlare 的任何其他 DNS 相关 API 调用也是如此。

这解释了五分钟的差距。

来自 Cloudflare:

Hi,

DNS updates should take place after about five minutes (the ttl is 300 seconds). It may take a little longer to propagate out everywhere on the web (recursive DNS caching by your ISP, for example).

关于nginx - nginx 的代理缓存超时/延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19012477/

相关文章:

c# - 相当于 Modify Headers Firefox Addon 的 .NET Native 应用程序

ruby-on-rails - 错误代码 : ssl_error_rx_record_too_long for https in nginx on ruby on rails application

django - 在 nginx 上无需用户刷新即可提供更新文件的正确方法

gwt - 测试异步 rpc

c++ - 如何使用 Boost 在 C++ 中制作代理服务器

http - HTTP 中介的请求处理模型

linux - 配置squid来处理相对url

nginx - docker —运行nginx并不总是有效

python - 使用 Nginx 反向代理部署 Pylons?

nginx - 使用 Istio 在两个 pod 之间进行简单的 http 请求