S
S
s_pyanov2021-08-26 08:55:37
Nginx
s_pyanov, 2021-08-26 08:55:37

Nginx routing for squid, how to configure?

Good day to all.
Task: set up an nginx front that, depending on server_name, redirects tcp packets to a specific squid docker container that relays traffic further.

Those. there are third-level
domains fr.example.com
gd.example.com
nl.example.com

In the browser proxy settings, one of the domains is specified and the traffic goes first to nginx, then nginx, depending on the third-level domain, redirects traffic to one of CERTAIN squid ports.

fr.example.com --> localhost:7000
gd.example.com --> localhost:7001
nl.example.com --> localhost:7002
...

if I write in /etc/nginx/nginx.conf

stream {
  upstream fr {
    server localhost:7000;
  }
  server {
    listen 8081;
    proxy_pass fr8081;
    proxy_responses 1;
  }
}

then it works based on port 8081, respectively, you cannot specify server_name in this block.

if I write in /etc/nginx/sites-enabled/config.config
upstream fr {
    server 127.0.0.1:3128;
}

server {
    listen 8080;
    server_name fr.example.com;

    location / {
       proxy_read_timeout 1800;
       proxy_connect_timeout 1800;
       proxy_send_timeout 1800;
       send_timeout 1800;
       proxy_set_header        Accept-Encoding   "";
       proxy_set_header        X-Forwarded-By    $server_addr:$server_port;
       proxy_set_header        X-Forwarded-For   $remote_addr;
       proxy_set_header        X-Forwarded-Proto $scheme;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_pass http://fr;
    }
}

then in the logs you get
"CONNECT www.google.com:443 HTTP/1.1" 400 166 "-" "-"

how can I solve the problem?
os:ubuntu 20.04

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Barbolin, 2021-08-26
@dronmaxman

> In the browser in the proxy settings, one of the domains is indicated
It will not work. Nginx server_name looks at the http header, and in it you pass www.google.com.
Better use different ports.
8080
8081
8082

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question