Skip to content

Instantly share code, notes, and snippets.

@doug-hoffman
Last active December 23, 2020 21:13
Show Gist options
  • Save doug-hoffman/a1c742f5213edbf6e5c5fc3b66ba640a to your computer and use it in GitHub Desktop.
Save doug-hoffman/a1c742f5213edbf6e5c5fc3b66ba640a to your computer and use it in GitHub Desktop.
nginx transparent reverse proxy for denonavr debug - replace $avr with the avr ip
auto lo:192
iface lo:192 inet static
address 192.168.123.45/32
table ip nat {
chain denon-intercept {
ip saddr 192.168.123.45 ip daddr $avr dnat to $avr
ip daddr $avr tcp dport 80 dnat to 192.168.123.45:8001
ip daddr $avr tcp dport 8080 dnat to 192.168.123.45:8002
ip daddr $avr tcp dport 60006 dnat to 192.168.123.45:8003
}
chain denon-intercept-remote {
type nat hook prerouting priority -101; policy accept;
jump denon-intercept
}
chain denon-intercept-local {
type nat hook output priority -101; policy accept;
jump denon-intercept
}
chain denon-forward {
type nat hook postrouting priority 99; policy accept;
ip saddr 192.168.123.45 oif "bond0" masquerade
}
}
log_format bodylog '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" $request_time '
'REQUEST:"$request_body" RESPONSE:"$resp_body"';
server {
listen 192.168.123.45:8001;
server_name localhost;
# http://serverfault.com/questions/361556/is-it-possible-to-log-the-response-data-in-nginx-access-log
access_log /var/log/nginx/avr.80.access.log bodylog;
lua_need_request_body on;
set $resp_body "";
body_filter_by_lua '
local resp_body = string.sub(ngx.arg[1], 1, 100000)
ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
if ngx.arg[2] then
ngx.var.resp_body = ngx.ctx.buffered
end
';
location / {
proxy_pass http://$avr:80;
proxy_bind 192.168.123.45;
}
}
server {
listen 192.168.123.45:8002;
server_name localhost;
# http://serverfault.com/questions/361556/is-it-possible-to-log-the-response-data-in-nginx-access-log
access_log /var/log/nginx/avr.8080.access.log bodylog;
lua_need_request_body on;
set $resp_body "";
body_filter_by_lua '
local resp_body = string.sub(ngx.arg[1], 1, 100000)
ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
if ngx.arg[2] then
ngx.var.resp_body = ngx.ctx.buffered
end
';
location / {
proxy_pass http://$avr:8080;
proxy_bind 192.168.123.45;
}
}
server {
listen 192.168.123.45:8003;
server_name localhost;
# http://serverfault.com/questions/361556/is-it-possible-to-log-the-response-data-in-nginx-access-log
access_log /var/log/nginx/avr.60006.access.log bodylog;
lua_need_request_body on;
set $resp_body "";
body_filter_by_lua '
local resp_body = string.sub(ngx.arg[1], 1, 100000)
ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
if ngx.arg[2] then
ngx.var.resp_body = ngx.ctx.buffered
end
';
location / {
proxy_pass http://$avr:60006;
proxy_bind 192.168.123.45;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment