Created
October 25, 2012 05:57
-
-
Save fukata/3950740 to your computer and use it in GitHub Desktop.
nginx proxy cache gzipped contents
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
http { | |
upstream web_backend { | |
server web01:80; | |
server web02:80; | |
} | |
proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=cache-space:100m max_size=1024m inactive=1h; | |
proxy_temp_path /var/cache/nginx/tmp; | |
server { | |
listen 80; | |
server_name example.com; | |
location / { | |
set $ae ""; | |
if ($http_accept_encoding ~* gzip) { | |
set $ae "gzip"; | |
} | |
proxy_no_cache 0; | |
proxy_cache_bypass 0; | |
proxy_cache cache-space; | |
proxy_cache_key $ae$scheme$host$uri$is_args$args; | |
proxy_cache_valid 200 5m; | |
proxy_redirect off; | |
proxy_next_upstream error timeout invalid_header http_500; | |
proxy_cache_use_stale error updating; | |
proxy_conneout 2; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-Host $host; | |
proxy_set_header X-Forwarded-Server $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Accept-Encoding $ae; | |
proxy_pass http://web_backend; | |
} | |
} | |
} |
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
http { | |
upstream web_backend { | |
server 127.0.0.1:12345; | |
} | |
gzip on; | |
gzip_http_version 1.0; | |
gzip_types text/plain | |
text/html | |
text/xml | |
text/css | |
application/xml | |
application/xhtml+xml | |
application/rss+xml | |
application/atom_xml | |
application/javascript | |
application/x-javascript; | |
gzip_disable "MSIE [1-6]\."; | |
gzip_disable "Mozilla/4"; | |
gzip_comp_level 6; | |
gzip_proxied any; | |
gzip_vary on; | |
gzip_buffers 4 8k; | |
gzip_min_length 1000; | |
server { | |
listen 80; | |
server_name example.com; | |
location / { | |
proxy_pass http://web_backend; | |
} | |
} | |
} |
It looks like server_name in second file must be changed to server_name web01 web02;
?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
they do not work.can not cache gzipped js/css