5

I'm using a variable to define my proxy_pass target, similar to this answer except in my case the value is extracted from a query param on the incoming request, so e.g. /?url=http://example.com will be proxied to example.com. Since the proxy_pass argument is a variable, I have no upstream directive in my config. The proxying works fine. However, the connection is closed after each request and I want to them alive to amortize the TCP handshake. According to these directions, that requires a keepalive directive in the upstream directive. How can I do this without an upstream directive?

Here's my full config:

server {
  if ($arg_url ~ \/\/([^\/]*)) {
    set $proxy_host $1; 
  }

  if ($proxy_host = "") {
    return 404;
  }

  resolver 8.8.8.8;
  location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";   

    proxy_set_header Host $proxy_host;
    proxy_pass $arg_url;
  }
}

0 Answers0