为您提供一些有关我的问题的背景信息:
我有一个可以安装软件并公开提供服务的应用程序。安装时:
- 将基本文件安装到根路径(即
/var/www/{site}
) - 创建一个新的 nginx 配置文件并将其放置在
/etc/nginx/sites-available/{site}
- 从
/etc/nginx/sites-enabled/{site} 创建到该文件的符号链接(symbolic link)
- 重新加载 nginx 配置:
service nginx reload
- 向 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/