我正在通过嵌入 img制作一个高负荷的网络统计系统.标记到网站.我想做的是: nginx从某个主机获取图像请求它给出了从文件系统托管小1px静态图像的答案此时它以某种方式将请求的标头传输到应用程序并关闭与主机的...
我正在通过嵌入< img>制作一个高负荷的网络统计系统.标记到网站.我想做的是:
> nginx从某个主机获取图像请求
>它给出了从文件系统托管小1px静态图像的答案
>此时它以某种方式将请求的标头传输到应用程序并关闭与主机的连接
我正在使用Ruby,我将制作一个纯机架应用程序来获取标题并将它们放入队列以进行进一步计算.
我无法解决的问题是,如何配置sphinx为Rack应用程序提供标头,并返回静态图像作为回复而无需等待Rack应用程序的响应?
此外,如果有更常见的Ruby解决方案,则不需要Rack.
解决方法:
一个简单的选择是在继续后端进程的同时尽快终止客户端连接.
server {
location /test {
# map 402 error to backend named location
error_page 402 = @backend;
# pass request to backend
return 402;
}
location @backend {
# close client connection after 1 second
# Not bothering with sending gif
send_timeout 1;
# Pass the request to the backend.
proxy_pass http://127.0.0.1:8080;
}
}
上面的选项虽然简单,但可能导致客户端在断开连接时收到错误消息. ngx.say指令将确保发送“200 OK”标头,并且由于它是异步调用,因此不会保留.这需要ngx_lua模块.
server {
location /test {
content_by_lua '
-- send a dot to the user and transfer request to backend
-- ngx.say is an async call so processing continues after without waiting
ngx.say(".")
res = ngx.location.capture("/backend")
';
}
location /backend {
# named locations not allowed for ngx.location.capture
# needs "internal" if not to be public
internal;
# Pass the request to the backend.
proxy_pass http://127.0.0.1:8080;
}
}
一个更简洁的Lua选项:
server {
location /test {
rewrite_by_lua '
-- send a dot to the user
ngx.say(".")
-- exit rewrite_by_lua and continue the normal event loop
ngx.exit(ngx.OK)
';
proxy_pass http://127.0.0.1:8080;
}
}
绝对是一个有趣的挑战.
沃梦达教程
本文标题为:ruby – 如何让nginx返回静态响应并向应用程序发送请求标头?
基础教程推荐
猜你喜欢
- go语言的魔幻旅程14-反射 2023-09-05
- Ruby on Rails在Ping ++ 平台实现支付 2023-07-22
- R语言学习代码格式一键美化 2022-12-05
- golang 自然语言处理工具(gohanlp) 2023-09-05
- R语言关联规则深入详解 2022-11-08
- Go语言实现一个Http Server框架(二) Server的抽象 2023-07-25
- ruby-on-rails – Nginx支持的Rails应用程序中缺少Content-Length Header 2023-09-20
- R语言使用gganimate创建可视化动图 2022-12-10
- R语言histogram(直方图)的具体使用 2022-10-28
- R语言多元线性回归实例详解 2022-12-15
