Access Internet Through Proxy

Hi Community! I have problem with accessing internet through proxy. Here’s the configuration.

frontend main
bind *:5000
#acl url_static path_beg -i /static /images /javascript /stylesheets
#acl url_static path_end -i .jpg .gif .png .css .js
#use_backend static if url_static
#default_backend app
use_backend %[req.hdr(Host),lower]
backend web1.com
server web1 localhost:8080 check
backend web2.com
server web2 localhost:8081 check
backend web3.com
server web3 localhost:8082 check

It should be error “Can’t be reach”.

What i want to make, if anyone want access youtube, the haproxy give access to outside.
Any solution? Thanks!

It’s really unclear. I guess you mean you are installing haproxy in front of another outgoing proxy like Squid so that haproxy is configured as the proxy in the browser, is that it ? But in this case why would you have 3 different hosts on 3 different ports ?

Also, you need to use “mode http” in your frontends and backends (or place that in a “defaults” section), otherwise the connections are forwarded in TCP without waiting for the request, and here you’ll end up failing to connect and directly closing in the face of the client, which might explain the error you’re receiving.

yup, i did the defaults section but not in copy that. Sorry for the unclear.

I have 3 website that can be access only by set the windows proxy into my ip and ports. The problem comes when i want to access internet like youtube, google, etc. I have to turn off the proxy setting first and i can watch the youtube. Is there any solution for that?

haproxy

OK got it.

Then you’re not using the right tool. Haproxy is a reverse proxy, not a forward proxy. Even using it like this in your browser will not work for SSL sites because your browser will send a CONNECT request that haproxy will forward to the server and that the server will not understand. You need to use a forward proxy to do what you describe. Squid ( http://squid-cache.org/ ) is the best known one, but there are others.

1 Like

wow thanks for the solution!

Moderator @willy notes (April’22):

Haproxy is a reverse proxy, not a forward proxy.

At HAProxyConf 2019, Julien Pivotto explains

how Inuits uses HAProxy in an unconventional way: as a forward proxy to route outgoing traffic.

I assume Julien had a special use case and HAProxy isn’t a typical forward proxy, can someone comment on the nuances?