Nginx: How to correctly use Time and Size postfix / parameters

Nginx: How to correctly use Time and Size postfix / parameters

I was struggling on figuring out why my cache size was not growing as intended. I had setup my configuration so that pages would be cached for a really long time but refreshed often. The idea being able to cache my entire site but at the same time having NginX frequently checking for new updates. If the backed or upstream server was down, then most likely a “stale” copy of the page would be available and served to the client. That way visitors would suffer of reduced downtime. But the problem I was having is that the cache was growing up to a point and then started to decrease and oscillated around a few mb. Long hours checking headers and debugging until I finally realized I wasn’t using the Time parameters correctly. I was indicating “m” in the configuration thinking that stood for months but then it hit me… What is the postfix for minute? So there you have it, my cache wasn’t growing because it was getting deleted shortly after it was saved. Quite the undesired behavior and result of my lack of attention.

Regardless if you make silly mistakes like I do, I always find myself in need of reference material to figure out what is the right postfix when using size or time parameters in NginX. Because of that I have prepared two tables to help anyone who is also in need of a quick reference when configuring Nginx:


By default when you specify a parameter of type size it is defaulted to bytes. If you wish to indicate something more practical you could use the postfix m or k. As fas as I am concerned g for gigabyte also works but then again I could not find it in the documentation. I have used it in my configuration file with nginx -t not complaining and the behavior looks correct (but truly I have not come close to the limit I set so I can’t say for sure)

Syntax Description
k, K kilobytes
m, M megabytes


There is more variety with the time parameters than with the sizes (doubtful many would need fore than g). Some might expect the default might be in milliseconds as that is the smaller unit that nginx recognizes, but it actually defaults to seconds.

Syntax Description
ms milliseconds
s seconds
m minutes
h hours
d days
w weeks
M Months (30 days)
y Years (365 days)

The cool thing with time is that you could combine different units. For example: “1h 30m” is used for one hour and thirty minutes. Obviously this is far cooler than having to type 90m. If you want to combine postfixes, you need to order them from most to least significant (30m 1h) would not work.

To keep up to date read the official documentation:

Enhanced by Zemanta

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.