Does nginx cache the unencrypted responses when using HTTPS?

ChocoDeveloper asked:

I thought public cache was not possible when using HTTPS since every response was different (due to encryption), but just now I realized one could at least cache the unencrypted response, and the only work the server would have to do is encrypt it for each new user.

Is that how it’s done by default? If not, can it be done?

I’m using nginx with fastcgi_cache.

My answer:

Yes, you can cache pages served via https.

Caching decision making is driven by the HTTP Cache-Control and Expires headers, nothing more.

However, typically they aren’t cached because Cache-Control is set to private because a user is logged into the site. If no user is logged in, you can make it public and then it becomes cacheable.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.