<div dir="ltr"><div>Hi all, <br></div><div><br></div><div>I fixed my issue with a simple application. Solution could be named "not named upstream support".<br></div><div>idea is that there is proxy_pass to upstream, and upstream is forwarding request to my local service (upstream server <a href="http://127.0.0.1:1981">127.0.0.1:1981</a>)<br></div><div>Under localhost <a href="http://127.0.0.1:1981">127.0.0.1:1981</a> my simple application is making requests to any server, and keeps connection alive. Control of all connection is under nginx - keepalive #value; keepalive_requests... app looks like:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">#!/bin/env python3<br>import sanic<br>import aiohttp<br>app = sanic.Sanic("gadula")<br>app.config.REQUEST_TIMEOUT = 60<br>app.config.KEEP_ALIVE_TIMEOUT = 60<br>aiohttp_timeout = aiohttp.ClientTimeout(<br> total=None,<br> connect=None,<br> sock_connect=10.0,<br> sock_read=120.0<br>)<br>@app.route("/<path:path>")<br>async def router(request, path):<br> try:<br> async with app.session.get(request.url, raise_for_status=True,<br> timeout=aiohttp_timeout) as r:<br> # TODO: Consider using Sanic's FileStreaming feature.<br> return sanic.response.raw(await r.read())<br> except aiohttp.ClientResponseError as e:<br> return sanic.response.json({<br> 'url': request.url,<br> 'error': str(e),<br> }, status=e.status)<br> except Exception as e:<br> return sanic.response.json({<br> 'url': request.url,<br> 'error': str(e),<br> }, status=500)<br>@app.listener('before_server_start')<br>async def setup(app, loop):<br> app.session = aiohttp.ClientSession()<br>@app.listener('after_server_stop')<br>async def setup(app, loop):<br> await app.session.close()<br>app.run(host="127.0.0.1", port=1981, debug=False, access_log=False)<br></blockquote><div>app is written in asynchronous mode, so can serve many nginx workers and generally it does the job, now I have nginx configuration which keeps konnection from <b>any</b> clients to <b>any</b> server.</div><div>question, why it cannot be done without any intermediate application??</div><div>any comments, suggestions are welcome!!</div><div><br></div><div>regards</div></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Łukasz Tasz<br></div><div>RTKW<br></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">czw., 8 paź 2020 o 12:16 Łukasz Tasz <<a href="mailto:lukasz@tasz.eu">lukasz@tasz.eu</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div>Hi, <br></div>sucha setup is on 1stproxy, there I have upstream defined to second proxy and it works - connection is reused.<br></div>problem is that it is chain of forward proxy with caching, and <a href="http://your-server.com" target="_blank">your-server.com</a> including port is different - service:port is dynamic. <br></div><div>I'm asking for it, because with firefox (set global proxy to my second proxy) I go to some <a href="http://blabla.your-server.com" target="_blank">blabla.your-server.com</a> connection is kept</div><div>in a meaning that on server side I see only one established connection, and all of requests that I make from firefox are made over this keept connection. Problem starts when I will use chain of proxies (all nginx).</div><div><br></div><div>regards</div><div><div><div><div><div><div dir="ltr"><div dir="ltr"><div>Łukasz Tasz<br></div><div>RTKW<br></div></div></div></div><br></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">czw., 8 paź 2020 o 11:43 Marcin Wanat <<a href="mailto:marcin.wanat@gmail.com" target="_blank">marcin.wanat@gmail.com</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 8, 2020 at 11:36 AM Łukasz Tasz <<a href="mailto:lukasz@tasz.eu" target="_blank">lukasz@tasz.eu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi all, <br></div><div><br></div>can I expect that proxy_pass will keep connection to remote server that is being proxied?<br><div><br></div><div>when I'm using setup client -> proxy -> server it looks to work<br></div><div>but when I'm using:<br></div><div>client -> 1stProxy_upstream -> proxy -> server<br></div><div>connection between 1stProxy and proxy is being kept thanks to keepalive 100, but proxy makes new connection every new request, very simple setup:<br><br></div><div>http {<br> server {<br> listen 8080;<br> location / {<br> keepalive_disable none;<br> keepalive_requests 1000;<br> keepalive_timeout 300s;<br> proxy_cache proxy-cache;<br> proxy_cache_valid 200 302 301 30m;<br> proxy_cache_valid any 1m;<br> proxy_cache_key $scheme://$http_host$request_uri;<br> proxy_pass $scheme://$http_host$request_uri;<br> proxy_http_version 1.1;<br> proxy_set_header Connection "";<br> }<br> }<br>}</div><div>I would expect that when client connects proxy and it works then it should also works when proxy connects upstream proxy....</div></div></blockquote><div><br></div><div>For keepalive in upstream proxy you shoud use upstream configuration block and configure keepalive in it:<br><br> upstream backend {<br> zone backend 1m;<br> server <a href="http://your-server.com" target="_blank">your-server.com</a>;<br> keepalive 128;<br>}</div><div><br></div><div>
server {<br> listen 8080;<br> location / {<br> proxy_cache proxy-cache;<br> proxy_cache_valid 200 302 301 30m;<br> proxy_cache_valid any 1m;<br> proxy_cache_key $scheme://$http_host$request_uri;<br> proxy_pass $scheme://backend$request_uri;<br> proxy_http_version 1.1;<br> proxy_set_header Connection "";<br> }<br> } <br></div><div><br></div><div>--</div><div>Marcin Wanat<br></div></div></div>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a></blockquote></div>
</blockquote></div>