DirectAdmin Knowledge Base and Support

DirectAdmin is a web panel for a simple administration of both virtual and dedicated servers. DirectAdmin is faster, safe and more powerful than any other CP. And we know how to customize and support it.

I have enabled proxy_cache in nginx and it does not work. How to fix it?

| 00:36:44 01.07.2016

It was noticed that caching does not work in NGINX if to try and enable it on a Directadmin server when using NGINX+Apache scheme. Here you can learn why...

How Does NGINX Determine Whether or Not to Cache Something? 

By default, NGINX respects the Cache-Control headers from origin servers. It does not cache responses with Cache-Control set to Private, No-Cache, or No-Store or with Set-Cookie in the response header. NGINX only caches GET and HEAD client requests. 

These defaults can be overwritten, and it goes out of a scope of this article. 

NGINX will not cache responses if proxy_buffering is set to off. It is on by default.

How Does it Relate with Directadmin?

Directadmin since version 1.46 has an option which disables proxy_buffering by default with NGINX+Apache scheme:

nginx_proxy_buffering=0

Thus to get the caching to work you need to enable proxy_buffering in NGINX by changing internal default value of nginx_proxy_buffering to 1 in directadmin.conf:

cd /usr/local/directadmin/conf/
cp -fp directadmin.conf{,~bak}
echo "nginx_proxy_buffering=1" >> directadmin.conf

Restart directadmin:

service directadmin restart

and rewrite configs:

cd /usr/local/directadmin/custombuild
./build update && ./build rewrite_confs

Enabling buffering in NGINX will mean that Apache sends all data to NGINX, which stores it in a buffer, which can then disconnect from Apache to let it do other things. 

The catch with enabled proxy_buffering is that NGINX doesn't start to send all of the data until Apache has finished sending it to NGINX... meaning the first byte is not sent until NGINX receives the last byte from Apache.

Used links:

  1. A Guide to Caching with NGINX
  2. NGINX docs: proxy_buffering
  3. Directadmin: nginx proxy to disable proxy_buffering by default
About Us
We are a team of professionals, and specialize in installation, configuring and managing of remote virtual and dedicated servers powered by Linux/Unix-like OS with DirectAdmin. We support various sets of software, including web-servers Apache, Nginx; internet domain name servers Bind, PowerDNS; mail-servers with POP3, IMAP and SMTP, FTP-servers, etc. After years of working through the most complex server challenges our team has gathered valuable experience and universal solutions suitable for everyday tasks. We are here to lend you a helping hand and take care of your servers in order to let you have enough time to do more of what you love.




All of the information and data on this site is for informational purposes only and is provided for the convenience of the user.
Powered by: Amiro.CMS - Free edition