Connect to upstream/backend via socks5 proxy in NginX/HAProxy

8,146

End up with a pure port forwarding solution instead of HAProxy or NginX. If anyone happens to come across the same usage scenario, here are some scripts I've been using to proxy domains inside Docker: https://github.com/w1ndy/docker-proxy-domain. Hope it helps!

Share:
8,146

Related videos on Youtube

skies457
Author by

skies457

Updated on September 18, 2022

Comments

  • skies457
    skies457 over 1 year

    I'm trying to make NginX or HAProxy use proxies while connecting to upstream URLs, something like this:

    Browser -> Nginx/HAProxy -- SOCKS5 Tunnel --> Remote
    

    I wonder if it's possible?

    Edited:

    Basically I would like to transparently proxy http requests:

    1. Set up a local DNS resolver (e.g. unbound) and rewrite DNS entries pointing some domains to localhost;

    2. NginX/HAProxy handles http requests based on their Host field (I'm also running a HTTP server) and proxies HTTP requests accordingly.

    It would be quite useful to provide access to blocked domains without too many configurations on client side (especially in a Docker container, it would be rather difficult if it's an official image).

    • Admin
      Admin over 7 years
      Any reason to use socks5 in particular? Vs, say, an ssh tunnel or iptables-based port forward? Then you don't have to use proxy logic at the nginx/haproxy level to support SOCKS. Maybe you could say a little more about your use case
    • Admin
      Admin over 7 years
      @DanFarrell I've edited the question and added some more details. I wonder if it's possible to do this?
    • Admin
      Admin over 7 years
      Is your real question about accessing "blocked domains"?
    • Admin
      Admin over 7 years
      @DanFarrell Since I'm already able to bypass restrictions through the SOCKS5 proxy, I'm curious if I could do it transparently (just by setting up a DNS resolver on a Docker host)
    • Admin
      Admin over 7 years
      You'll need to either implement the feature in nginx/haproxy as module or use something like this github.com/normanr/socks-tun.