Score:0

Use squid to forward http(s) requests based on domainname

cn flag

I have installed 5 LXC containers in Proxmox. Each container has a Apache2 webserver up and running inside, pointing to a registered domain.

So:
container1 points to example1.com and has a local ip address of 192.168.2.225
container2 points to example2.com and has a local ip address of 192.168.2.230
container3 points to example3.com and has a local ip address of 192.168.2.235
and so on.

I would like to forward requests for the 5 different domains to the according container. All containers have static ip's and are bridged on vmbr0 to the physical NIC (enp3s0)

So I tried to achieve it with a separate container, running Squid proxy,with a local ip address of 192.168.2.253 and port 3128, which is Squid's default listening port.

First I had setup iptables on the Proxmox host with the following rules:

iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 22 -j DNAT --to 192.168.2.253:3128
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 192.168.2.253:3128
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 192.168.2.253:3128
iptables --t nat -A POSTROUTING --out-interface vmbr0 -j MASQUERADE

After that I tried to configure Squid:

http_port 3128
http_access allow all
http_port 3128 intercept
visible_hostname squid.proxy


acl 100 dstdomain .example1.com
acl 101 dstdomain .example2.com
acl 102 dstdomain .example3.com

cache_peer 192.168.2.225 parent 80 0 no-query
cache_peer 192.168.2.230 parent 80 0 no-query
cache_peer 192.168.2.235 parent 80 0 no-query

When browsing to example1.com, I am notified by Squid with the message:

The requested URL could not be retrieved

My question is: what can I do to forward each domain successfully to it's according container?

vidarlo avatar
ar flag
Does this answer your question? [What is a Reverse Proxy?](https://serverfault.com/questions/8654/what-is-a-reverse-proxy)
djdomi avatar
za flag
i would just suggest, that you dont use nat, but nginx on the host as i do and forward via reverse proxy function to the hosts geneerell a nat is still required imho
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.