Skip to content

Instantly share code, notes, and snippets.

@dergachev
Last active December 18, 2015 09:19
Show Gist options
  • Save dergachev/5760400 to your computer and use it in GitHub Desktop.
Save dergachev/5760400 to your computer and use it in GitHub Desktop.
nginx dirty debugging trick

nginx dirty debugging

Like PHP's die() or ruby's raise, but for nginx config files.

Option 1, have external webservice to echo out the variable of interest:

rewrite ^ http://httpbin.org/get?abuse=$abuse last; break;

Option 2: just include it in HTTP headers:

    root /var/www/nginx-default;
    
    location / {
      add_header X-nginx-abuse $abuse;
      add_header X-nginx-bad-bot $bad_bot;
      try_files $uri @apache;
    }
    location @apache {
      proxy_pass http://127.0.0.1:80;
      proxy_set_header Host $host;
    }

Note that add_header doesn't work on pages with error (404/403/etc), see see http://wiki.nginx.org/HttpHeadersModule#add_header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment