E
E
Esergion2014-02-06 12:23:44
Nginx
Esergion, 2014-02-06 12:23:44

How can Nginx not give the client a response from an asynchronous POST echo_subrequest_async?

Hello, there is an application in which it would be necessary to collect statistics when accessing
location / open and location / load
At the moment, the following has been done:

upstream app_server{
        server 127.0.0.1:7101; # основное приложение
    }
upstream stat_app_server{
  server 127.0.0.1:9292; # для сбора статистики
    }
server {
        listen 80 default_server;
        location / {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
         ..........
          if (!-f $request_filename) {
            proxy_pass http://app_server;
            break;
          }
        }
        # Rails error pages
        error_page 500 502 503 504 /500.html;
        location = /500.html {
          root .....-major/current/public;
        }
location /open {
      echo_subrequest_async POST '/openstat' -q 'uri=$request_uri&refer=$http_referer&ip=$remote_addr';
      proxy_pass http://app_server/open;
  }
location /load {
      echo_subrequest_async POST '/loadstat' -q 'uri=$request_uri&refer=$http_referer&ip=$remote_addr';
      proxy_pass http://app_server/load;
  }
  location /openstat {
      proxy_pass http://stat_app_server/openstat;
  }
  location /loadstat {
      proxy_pass http://stat_app_server/loadstat;
  }
}

As a result, when asked
http://app_url/open
given a blank page from
proxy_pass http://stat_app_server/openstat;
but not from
proxy_pass http://app_server/open;

Help to force nginx not to return the result of an asynchronous request. Or is another config possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Esergion, 2014-04-08
@Esergion

I'll post the solution just in case.
used the lua module, with requests like this in the required locations:

access_by_lua 'res = ngx.location.capture("/loadstat",
  { args = { uri = ngx.var.request_uri, refer = ngx.var.http_referer, ip = ngx.var.remote_addr }})';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question