Nginx as forward proxy and maintaining persistent connections
Maxim Dounin
mdounin at mdounin.ru
Sat Mar 24 15:06:46 UTC 2018
Hello!
On Fri, Mar 23, 2018 at 08:17:09PM -0400, vi54 wrote:
> am trying to configure nginx as a forward proxy and establish persistent
Note that nginx is not a forward proxy. You may have better luck
with other programs which are designed to be used as a forward
proxy.
> connection between the nginx and the upstream server. When I set
>
> server {
> location / {
> proxy_pass http://$http_host$request_uri;
> proxy_http_version 1.1;
> proxy_set_header Connection "";
> ...
> }
> }
> in the location context, it has no effect until I have a upstream module
> that has keepalive directive in it. Is it mandatory to specify the upstream
> module with keepalive directive?
Yes, to maintain keepalive connections with an upstream server you
have to define and upstream{} block with keepalive cache
configured.
> If I do that way,
>
> http
> {
> upstream up {
> server $http_host;
> keepalive 20;
> }
> server {
> proxy_pass http://up$request_uri;
> }
> }
> I get the error host not found in upstream "$http_host". Looks like the
> server directive is not using it as variable but merely looking for a server
> named $http_host? I tried finding hints in online resources but couldn't get
> help. I need someone to point me how this goes wrong?
That's expected, you cannot use variables in the "server"
directive in the upstream block.
That is, what you are trying to do won't work. You can only
maintain persistent connections with upstream servers you know
about and configured in advance.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx
mailing list