Skip to content

Instantly share code, notes, and snippets.

@sirsquidness
Created September 22, 2016 12:42
Show Gist options
  • Save sirsquidness/710bc76d7bbc734c7a3ff69c6b8ff591 to your computer and use it in GitHub Desktop.
Save sirsquidness/710bc76d7bbc734c7a3ff69c6b8ff591 to your computer and use it in GitHub Desktop.

Revisions

  1. sirsquidness created this gist Sep 22, 2016.
    46 changes: 46 additions & 0 deletions proxy.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@

    # This config came around after a friend had problems with a Steam cache on his
    # Cox internet connection. Cox would intercept any requests to Steam content
    # servers and return a 302 to Cox's servers. The cache would return the 302
    # to the Steam client, and the Steam client would go directly to Cox, bypassing
    # the cache.
    # This config makes nginx follow the 302 itself, and caches the result of the
    # redirect as if it was the response to the original request. So subsequent
    # requests to the URL that returned a 302 will get the file instead of a 302.


    proxy_cache_path /cache keys_zone=steam:100m levels=1:2 inactive=100d max_size=1000g;

    server {
    listen 80;
    charset utf-8;

    client_max_body_size 75M;

    # main cache block - when upstream responds with a 302, it's caught by
    # error_page and passed off to the (nearly identical) @handle_redirects
    location / {
    proxy_pass http://web;
    proxy_cache steam;
    proxy_cache_key $uri;
    proxy_cache_valid 200 206 3000h;
    proxy_intercept_errors on;
    error_page 301 302 307 = @handle_redirects;
    }

    location @handle_redirects {
    #store the current state of the world so we can reuse it in a minute
    # We need to capture these values now, because as soon as we invoke
    # the proxy_* directives, these will disappear
    set $original_uri $uri;
    set $orig_loc $upstream_http_location;

    # nginx goes to fetch the value from the upstream Location header
    proxy_pass $orig_loc;
    proxy_cache steam;
    # But we store the result with the cache key of the original request URI
    # so that future clients don't need to follow the redirect too
    proxy_cache_key $original_uri;
    proxy_cache_valid 200 206 3000h;
    }
    }