nginx caching
Post on 09-Jan-2017
310 Views
Preview:
TRANSCRIPT
TYPES OF CACHING
• Browser or Client Side Cache
• Proxy or Remote Cache
• Gateway Cache or Reverse Proxy Cache or Surrogate Cache
BROWSER OR CLIENT SIDE CACHE
• built into browser
• uses user’s local memory
• can be used for ‘offline mode’
• user can configure this
PROXY OR REMOTE CACHE
• On network infrastructure like firewall or VPN or packet shapers
• Configured by network administrators
• Can be used to control content as well as serve it
WHAT IS CACHINGStoring Stuff Somewhere for “easy” retrieval later
Browser Firewall
Web Server
Load Balancer
CDN
Application Server
Database
LB Cache
Server Cache
App Cache
Browser Cache
STATIC VS DYNAMIC CONTENT
• Assets (images, css, js)
• Static Pages (rendered html)
• VS
• Pages that change based on user input, relayed information, or updated data (forms, chats/games, database/CMS)
HOW TO CACHE WITH NGINX
• proxy_cache_path - directive to configure your cache (where, how, name, etc…)
• proxy_cache - location directive to specify your cache by name (the one you configured above)
HTTP CACHE Headers (a selection)
• cache-control
• cache-control: private, max-age=0, no-cache
• expires (max-age overrides this)
• etag - entity-tag
• every update to a cached resource generates a new tag
• how to check if you need to get a new version of the resource
• private | public (user specific cache like a cookie vs shared cached resource like and image)
• no-cache (uses etag for revalidation)
• no-store (don’t cache this)
SIMPLE EXAMPLEpics are cached on the nginx cache server
*not actually using proxy_pass - it’s all on the same server
HOW TO TEST• I used the rails request logs vs the nginx request logs to test
my simple example (also look at the cache folder after the first request)
• As a user you can use inspect and the network tab - where are the assets coming from - and inspect the headers - you can see HIT or MISS
• Cache Monitoring (NGINX Plus does this for you) - New Relic is great for this
A WORD ON SSL• Cache the connection
parameters for the session (Speedy SSL)
• ssl_session_cache
• ssl_session_timeout
• SSL Offloading w/ Nginx caches the static content as normal at the Nginx reverse proxy server
RESOURCES• NGINX Guides
• https://www.nginx.com/blog/nginx-caching-guide/
• NGINX Content Caching • https://www.nginx.com/resources/admin-guide/
content-caching/• Beginners Guide to CACHE Headers
• http://dev.mobify.com/blog/beginners-guide-to-http-cache-headers/
• Optimizing HTTPS with NGINX • https://bjornjohansen.no/optimizing-https-nginx
top related