Skip to content

Instantly share code, notes, and snippets.

@peerapach
Last active August 14, 2019 09:29
Show Gist options
  • Save peerapach/233b5a749f2a1af1f2a5ad18f0e66d7d to your computer and use it in GitHub Desktop.
Save peerapach/233b5a749f2a1af1f2a5ad18f0e66d7d to your computer and use it in GitHub Desktop.
proxy_buffering on;
proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
limit_req_zone $binary_remote_addr zone=five_per_second:10m rate=5r/s;
limit_req_zone $binary_remote_addr zone=ten_per_one_minute:10m rate=10r/m;
server {
listen 80;
server_name www.ezylinux.com;
set $do_not_cache "0";
if ( $request_method !~ ^(GET|HEAD)$ ) {
set $do_not_cache "1";
}
location ~* ^/(index\.php/)?catalogsearch/(ajax) {
limit_req zone=ten_per_one_minute;
proxy_pass http://127.0.0.1:8080;
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-Forwarded-Proto $scheme;
proxy_cache STATIC;
proxy_cache_key "$host$request_uri$cookie_user";
proxy_cache_valid 200 301 302 120m;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_no_cache $do_not_cache;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|txt|wof)$ {
if ($request_method != GET) {
return 403;
}
access_log off;
expires max;
proxy_pass http://127.0.0.1:8080;
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-Forwarded-Proto $scheme;
proxy_cache STATIC;
proxy_cache_key "$host$request_uri$cookie_user";
proxy_cache_valid 200 301 302 1d;
proxy_cache_valid 404 10m;
proxy_cache_methods GET;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_no_cache $do_not_cache;
proxy_cache_bypass $http_x_purge_header;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
}
location / {
limit_req zone=five_per_second burst=10;
limit_rate 5m;
proxy_pass http://127.0.0.1:8080;
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-Forwarded-Proto $scheme;
proxy_cache STATIC;
proxy_cache_key "$host$request_uri$cookie_user";
proxy_cache_valid 200 301 302 120m;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_no_cache $do_not_cache;
proxy_cache_bypass $http_x_purge_header; #curl -H "X-Purge: 1"
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
add_header X-Cached $upstream_cache_status;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment