Welcome! Log In Create A New Profile


nginx to redirect http/https traffic based on url

Posted by mark.gargan 
nginx to redirect http/https traffic based on url
December 06, 2021 10:22AM
I'm trying to setup nginx to allow me to redirecct traffic through one of two outbound proxies on our internal lan

I'm using the nginx docker image as he's baked it with the ngx_http_proxy_connect_module pre-loaded

when I start the image I can hit www.google.com through the nginx proxy as follows
curl -v -k --proxy http://localhost:8888 www.google.com

and I can see the request successfully passing through my proxy server running on port 8889, however, when I try to access google over https I get a 400
curl -v -k --proxy http://localhost:8888 https://www.google.com

The following are the output lines in the access.log for the http and https requests respectively
--------- - - [06/Dec/2021:13:35:51 +0000] www.google.com 200 15878 "-" "curl/7.64.1" "-" - - [06/Dec/2021:13:35:31 +0000] www.google.com:443 http://:- 400 166 "-" "curl/7.64.1" "-"

Would anyone have any idea why I can proxy the http request but not the https request?

Nginx is configured with the nginx.conf as follows :-

user www-data;
worker_processes auto;
daemon off; # Don't run Nginx as daemon, as we run it in Docker we need a foreground process.
events { }

http {
# google's DNS server
resolver_timeout 5s;

log_format custom_log_format '$remote_addr - $remote_user [$time_local] $http_host'
' $scheme://$external_host:$external_port$request_uri $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';

access_log /dev/stdout custom_log_format;
error_log /dev/stderr;
proxy_temp_path ./temp;

server {
# proxy server port
listen 8888;

location / {

# external proxy
set $external_host "";
set $external_port "8889";

# proxy (default)
set $proxy_host "$http_host";
set $url "$scheme://$external_host:$external_port$request_uri";
proxy_redirect off;
proxy_set_header Host $proxy_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_pass "$url";

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 114
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