如何让nginx返回静态响应并将请求标头发送到应用程序?

san*_*rew 5 ruby rack high-load nginx

我正在通过将<img>标记嵌入到网站来制作高负荷的网络统计系统.我想做的是:

  1. nginx从某个主机获取图像请求
  2. 它给出了从文件系统托管小1px静态图像的答案
  3. 此时,它以某种方式将请求的标头传输到应用程序并关闭与主机的连接

我正在使用Ruby,我将制作一个纯机架应用程序来获取标题并将它们放入队列以进行进一步计算.

我无法解决的问题是,如何配置sphinx为Rack应用程序提供标头,并返回静态图像作为回复而无需等待Rack应用程序的响应?

此外,如果有更常见的Ruby解决方案,则不需要Rack.

kol*_*ack 1

您也许可以使用post_action来完成此任务(我不完全确定这会起作用,但这是我能想到的唯一的事情)

server {
  location / {
    post_action @post;
    rewrite ^ /1px.gif break;
  }

  location @post {
    # Pass the request to the backend.
    proxy_pass http://backend$request_uri;

    # Using $request_uri with the proxy_pass will preserve the original request,
    # if you use (fastcgi|scgi|uwsgi)_pass, this would need to be changed.
    # I believe the original headers will automatically be preserved.
  }
}
Run Code Online (Sandbox Code Playgroud)