Created
June 26, 2015 01:48
-
-
Save zeroasterisk/ffb85ef4f0b7b5ae2d5b to your computer and use it in GitHub Desktop.
nginx config (partial) caching reverse proxy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------¬ | |
# Proxy config/example | |
# (optional config used inside server/location blocks)¬ | |
# context - server, location¬ | |
# link: http://wiki.nginx.org/HttpProxyModule#proxy_cache¬ | |
# link: http://nginx.org/en/docs/http/ngx_http_proxy_module.html¬ | |
# link: http://nginx.org/en/docs/http/ngx_http_upstream_module.html | |
# link: http://www.packtpub.com/article/using-nginx-reverse-proxy¬ | |
# ----------------------------¬ | |
upstream adappservers { | |
# hash on IP for sticky sessions: or least_conn, least_time | |
ip_hash; | |
server 10.x.x.x max_fails=3 fail_timeout=30s; | |
server 10.x.x.x max_fails=3 fail_timeout=30s; | |
server 10.x.x.x backup; | |
} | |
location / { | |
proxy_pass https://adappservers; | |
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; | |
proxy_redirect off; | |
#proxy_buffering off; | |
¬ | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Remote-Port $remote_port; | |
proxy_set_header QUERY_STRING $query_string; | |
¬ | |
client_max_body_size 10m; | |
client_body_buffer_size 128k; | |
proxy_connect_timeout 90; | |
proxy_send_timeout 90; | |
proxy_read_timeout 90; | |
proxy_buffers 32 4k; | |
proxy_cache_valid 200 302 90m; | |
proxy_cache_valid 404 1m; | |
#can include whatever to make cache keys unique (cookie?)¬ | |
proxy_cache_key $scheme$proxy_host$request_uri; | |
# must be hit X times before cached¬ | |
#proxy_cache_min_uses 1; | |
# use cache even if stall, if we get back a timeout, error, etc. | |
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504 http_404; | |
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment