NGINX Timer Resolution

Using ngx.time or ngx.now is encouraged over using Lua’s built in functions because they use the cached time rather than performing a syscall, but how often is the cache updated?

After a bit of a dig, it turns out there’s no absolute answer, because the cache is actually updated when a kernel event fires:

It can be set manually using nginx’s timer_resolution
http://nginx.org/en/docs/ngx_core_module.html#timer_resolution
but this is not recommended because it either causes too many syscalls if set too low, or necessary time lag if set too high.

https://groups.google.com/d/msg/openresty-en/OdNzfh8rlzk/EQHF-hlhlQ0J

NGINX DNS in docker

Problem:

Docker runs its own container DNS that means you can easily link containers together just by specifying their names, instead of having to work out their dynamically assigned IP’s somehow. Unfortunately NGINX doesn’t read the /etc/hosts file that docker edits, and so can’t resolve hostnames of other containers.

Solution:

An earlier hacky solution was to bundle dnsmasq in with nginx and have it use 127.0.0.1 as a resolver, violating the one process per container best practice.

As of Docker 1.10 you can use the new embedded DNS feature by setting 127.0.0.11 as the resolver in nginx.conf, just be aware that there are issues with IPv6.