Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Created October 14, 2019 19:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arehmandev/a98822146fbeecbf162e20b125535e7e to your computer and use it in GitHub Desktop.
Save arehmandev/a98822146fbeecbf162e20b125535e7e to your computer and use it in GitHub Desktop.
Nginx transparent proxy
events {
worker_connections 1024;
}
http {
# google's DNS server
resolver 8.8.8.8;
resolver_timeout 5s;
server {
# proxy server port
listen 3128;
location / {
# local http server host and port
set $devel_host "127.0.0.1";
set $devel_port "80";
# proxy (default)
set $proxy_host "$http_host";
set $url "$scheme://$http_host$request_uri";
# http://any.with.suffix.devel/path
if ($host ~* "^(.+)\.devel$") {
set $proxy_host "$1";
set $url "http://$devel_host:$devel_port$request_uri";
}
# http://any.with.suffix.devel:8000/path
if ($http_host ~* "^(.+)\.devel:(\d+)$") {
set $proxy_host "$1:$2";
set $url "http://$devel_host:$2$request_uri";
}
proxy_redirect off;
proxy_set_header Host $proxy_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_pass "$url";
}
# access policy denies global ip addresses
allow 127.0.0.1/32;
allow 192.168.0.0/16;
allow 172.16.0.0/12;
allow 10.0.0.0/8;
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment