Skip to content

Instantly share code, notes, and snippets.

@Enelar
Last active August 29, 2015 14:23
Show Gist options
  • Save Enelar/5008857383fc0b755d8e to your computer and use it in GitHub Desktop.
Save Enelar/5008857383fc0b755d8e to your computer and use it in GitHub Desktop.
Using nginx as forward proxy for bad connection locations
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 300;
gzip on;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_proxied no-store no-cache private expired auth;
gzip_comp_level 8;
tcp_nodelay on;
tcp_nopush on;
sendfile on;
server {
listen 8080;
try_files @direct @auth;
location @direct {
set $auth "NO";
if ($http_cookie ~* "AUTH_COOKIE=([a-z0-9]+)(?:;|$)") {
set $auth $1;
}
resolver 8.8.8.8;
if ($auth !~ "NO") {
proxy_pass http://$http_host$uri$is_args$args;
}
}
location @auth {
auth_basic "You should enter credetials";
auth_basic_user_file htpasswd;
resolver 8.8.8.8;
proxy_pass http://$http_host$uri$is_args$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment