Skip to content

Instantly share code, notes, and snippets.

@cybersholt
Forked from noogen/nginx-proxy.conf
Created August 22, 2018 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybersholt/3ca4218d485e0fac4e40404672cc4495 to your computer and use it in GitHub Desktop.
Save cybersholt/3ca4218d485e0fac4e40404672cc4495 to your computer and use it in GitHub Desktop.
nginx proxy example
# https://www.scalescale.com/tips/nginx/nginx-proxy-cache-explained-2/
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=my_diskcached:10m max_size=5g inactive=45m use_temp_path=off;
server {
listen 80;
set $cache_uri $uri;
server_name example.com;
location ~ /purge(/.*) {
proxy_cache_purge my_diskcached acme.mycachedefault$uri$is_args$args;
}
# default fallback proxy
# set cache for 24 hours
location / {
gzip on;
gzip_min_length 100;
gzip_types text/plain text/xml application/xml text/css text/javascript application/javascript application/x-javascript text/x-component application/json application/xhtml+xml application/rss+xml application/atom+xml application/vnd.ms-fontobject image/svg+xml application/x-font-ttf font/opentype application/octet-stream;
gzip_comp_level 1;
gzip_disable "MSIE [1-6]\.";
expires 24h;
# ProxySettings
proxy_set_header Host your-origin-hostname.com;
proxy_hide_header access-control-allow-origin;
add_header Access-Control-Allow-Origin "*";
add_header X-Cache $upstream_cache_status;
proxy_cache_lock on;
proxy_cache_lock_timeout 60s;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_hide_header X-Cache;
proxy_ignore_headers Vary;
proxy_ignore_headers Expires;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers Cache-Control;
proxy_pass http://your-origin-hostname.com;
proxy_pass_header P3P;
proxy_cache_min_uses 2;
proxy_cache my_diskcached;
proxy_cache_valid 200 24h;
proxy_cache_key acme.mycachedefault$uri$is_args$args;
# END ProxySettings
}
# resize proxy with cache of 12 hours
location ~ /resize/(.*) {
gzip on;
gzip_min_length 100;
gzip_types text/plain text/xml application/xml text/css text/javascript application/javascript application/x-javascript text/x-component application/json application/xhtml+xml application/rss+xml application/atom+xml application/vnd.ms-fontobject image/svg+xml application/x-font-ttf font/opentype application/octet-stream;
gzip_comp_level 1;
gzip_disable "MSIE [1-6]\.";
expires 12h;
# ProxySettings
proxy_set_header Host imageproxy.example.com;
proxy_hide_header access-control-allow-origin;
add_header Access-Control-Allow-Origin "*";
add_header X-Cache $upstream_cache_status;
proxy_cache_lock on;
proxy_cache_lock_timeout 60s;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_hide_header X-Cache;
proxy_ignore_headers Vary;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers Expires;
proxy_ignore_headers Cache-Control;
proxy_pass http://imageproxy.example.com:4593/$1?$args;
proxy_pass_header P3P;
proxy_cache_min_uses 2;
proxy_cache my_diskcached;
proxy_cache_valid 200 12hr;
proxy_cache_key acme.mycachedefault$uri$is_args$args;
# END ProxySettings
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment