Welcome! Log In Create A New Profile

Advanced

nginx proxy to external proxy

Posted by mabr3 
nginx proxy to external proxy
August 11, 2020 06:31AM
Hi! I need to configure an nginx proxy that directs requests to another proxy and I'm having some trouble. Here's the context: We have machine A from where the request comes from, machine B where the nginx proxy will be and machine C where an external proxy is (squid). Only C has access to the internet and A has no connectivity with C. Therefore I need to go from A to B to C to the required website.

Here's what my conf looks like (the relevant part):

server {
listen Bport;
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://Cip:Cport;
}
}

But whenever I do something like:

curl -v -x http://Bip:Bport https://google.com

I get:

About to connect() to proxy Bip port Bport (#0)
* Trying Bip... connected
* Connected to Bip (Bip) port Bport (#0)
* Establish HTTP proxy tunnel to google.com:443
> CONNECT google.com:443 HTTP/1.1
> Host: google.com:443
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 400 Bad Request
< Server: nginx/1.10.1
< Date: Tue, 11 Aug 2020 10:03:27 GMT
< Content-Type: text/html
< Content-Length: 173
< Connection: close
<
* Received HTTP code 400 from proxy after CONNECT
* Closing connection #0
curl: (56) Received HTTP code 400 from proxy after CONNECT

Whereas if I use the external proxy directly (starting from B):

curl -v -x http://Cip:Cport https://google.com

The request goes through and everything works OK. Can someone provide some insight on this? Thanks in advance.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 69
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready