Skip to main content

Leverage browser caching in nginx

Comments

11 comments

  • cPRex Jurassic Moderator
    Hey there! I can't say I'm familiar with that exact configuration, but details on the caching with our Nginx reverse proxy installation can be found here:
    0
  • yaashul
    I am not asking about proxy caching. I am asking about content served by nginx and caching from browsers.
    0
  • cPRex Jurassic Moderator
    Thanks for that clarification. I believe this portion of that link would be still be relevant: "If your application uses GET or HEAD requests for dynamic content and does not include cache control headers, the server may return cached responses that do not apply to the user. To correct this issue, perform one of the following actions:
    0
  • tbutler
    I'm trying to figure out this question, too. The NGINX Manager suggestion doesn't apply since this is about _browser_ caching rather than _server side_ caching. I created a new include in server-includes with code like @yaashul's but it doesn't seem to get included. I was able to add it to the conf.d/users/[username] folder, but I'd like to apply it to all users, not have to do it individually for each username. Is there a way to apply it to every NGINX user?
    0
  • cPRex Jurassic Moderator
    I spoke with one of the Nginx developers about this issue and while using the include system is the only option, you could make it a bit easier with symlinks. For example, if your username is "username" you could do this: -create your custom cache configuration file in /etc/nginx/conf.d/includes-optional/ -use symlinks to that like this: /etc/nginx/conf.d/users/username/cache_customizations.conf would be a symlink to /etc/nginx/conf.d/includes-optional/cache_customizations.conf That would save you from needing to recreate the file each time.
    0
  • tbutler
    Thanks for your help. That does help, at least! The
    0
  • cPRex Jurassic Moderator
    It's still supported, I'm just not sure if those particular values will work well in that area. It wouldn't hurt to try it out though as it could be easily removed if it didn't perform how you expected.
    0
  • tbutler
    Thanks, I tried that, but it didn't seem to do anything when I added it in server-includes. Which makes some sense, because the cPanel generated template for each server block doesn't reference the conf.d/server-includes directory for some reason.
    0
  • cPRex Jurassic Moderator
    Thanks for that - I did re-check with our Nginx guys and there isn't going to be a one-and-done global solution for this particular behavior.
    0
  • tbutler
    Thanks! Do you think they"d be receptive to a feature request? It doesn"t just have to be about caching (although being able to follow Google"s official "Lighthouse" best practices on this matter " when it is such a straight forward fix seems like a worthy request), but it"d also be relevant for *any* other reason one may need to deploy an adjusted nginx setup for one"s clients, not just this one issue.
    0
  • cPRex Jurassic Moderator
    Oh for sure - always feel free to submit a feature request! You can do that right from the link in my signature.
    0

Please sign in to leave a comment.