消息“X-Accel-Mapping头丢失”在 Nginx 错误日志中
我正在 Ubuntu 8.04 上使用 Nginx 1.0.0 和 Passenger 3.0.7 运行 Rails 3 站点。
在我的 Nginx error.log 中,我开始看到很多消息 X-Accel-Mapping header丢失
。谷歌搜索引导我找到了 Rack::Sendfile
以及 Nginx 文档。
现在,我的应用程序可以通过多个域访问,并且我在应用程序中使用 send_file
来传送一些特定于它们所请求的域的文件,例如,如果您访问 domain1.com /favicon.ico
我在 public/websites/domain1/favicon.ico
中查找 favicon。 这工作正常,我认为我不需要/不想让 Nginx 参与并创建一些存储这些文件的私有区域,如 Rack::Sendfile
文档 建议。
我怎样才能摆脱错误消息?
I am running a Rails 3 site on Ubuntu 8.04 with Nginx 1.0.0 and Passenger 3.0.7.
In my Nginx error.log I started seeing the message X-Accel-Mapping header missing
quite a lot. Googling lead me to the docs of Rack::Sendfile
and to the Nginx docs.
Now, my app can be accessed through several domains and I am using send_file
in my app to deliver some files specific to the domain they are requested from, e.g., if you come to domain1.com/favicon.ico
I look up the favicon in at public/websites/domain1/favicon.ico
.
This works fine and I don't think I need/want to get Nginx involved and create some private area where I store those files, as the samples in the Rack::Sendfile
docs suggest.
How can I get rid of the error message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此消息意味着
Rack::Sendfile
为您禁用了X-Accel-Redirect
,因为您在 nginx.conf 中缺少它的配置...我正在使用 < em>Nginx + Passenger 3 + Rails 3.1。
从这个页面收集信息我已经弄清楚了:
http://wiki.nginx.org/X-加速
http://greenlegos.wordpress.com/2011/09/12/sending-files-with-nginx-x-accel-redirect
http://code.google.com/p/substruct/source/browse/trunk/gems/rack-1.1.0/lib/rack/sendfile.rb?r=355
通过 Rails 通过 Nginx 提供大文件2.3 使用 x-sendfile
我有一个控制器,它将
/download/1
请求映射到具有自己的目录结构的存储文件,如下所示:storage/00/00/1< /code>、
storage/01/0f/15
等。所以我需要通过 Rails 传递它,但随后我需要使用send_file
方法,该方法将使用X-Accel-Redirect
通过 nginx 直接将最终文件发送到浏览器。在代码中,我有这样的内容:
为此示例目的,我替换了文件名
现在,我必须将这些行添加到我的
nginx.conf
中:路径
/storage< /code> 从外部世界看不到,它仅在内部可见。
Rack::Sendfile
获取标头X-Accel-Mapping
,从中提取路径并将/var/www/shared/storage
替换为/存储...
。然后它会吐出修改后的标头:然后由nginx处理。
我可以看到它工作正常,因为文件下载速度比以前快了 100 倍,并且日志中没有显示错误。
希望这有帮助。
this message means that
Rack::Sendfile
disabledX-Accel-Redirect
for you, because you have missing configuration for it in nginx.conf...I'm using Nginx + Passenger 3 + Rails 3.1.
Gathered information from this pages I've figured it out:
http://wiki.nginx.org/X-accel
http://greenlegos.wordpress.com/2011/09/12/sending-files-with-nginx-x-accel-redirect
http://code.google.com/p/substruct/source/browse/trunk/gems/rack-1.1.0/lib/rack/sendfile.rb?r=355
Serving Large Files Through Nginx via Rails 2.3 Using x-sendfile
I have controller which maps
/download/1
requests to storage files which have their own directory structure, like this:storage/00/00/1
,storage/01/0f/15
etc. So I need to pass this through Rails, but then I need to usesend_file
method which will useX-Accel-Redirect
to send the final file to the browser through nginx directly.Within the code I have this:
I replaced the filename for this example purposes
Now I had to add these lines to my
nginx.conf
:The path
/storage
is not visible from outside world, it is internal only.Rack::Sendfile
gets the headerX-Accel-Mapping
, extracts the path from it and replaces/var/www/shared/storage
with/storage...
. Then it spits out the modified header:which is then processed by nginx.
I can see this works correctly as the file is downloaded 100x faster than before and no error is shown in the logs.
Hope this helps.
我们使用了与 NoICE 描述的类似技术,但我用描述包含包含文件的文件夹的文件夹的正则表达式替换了包含所有文件的“硬编码”目录 。
听起来很难,是吗?只需看一下这些(
/etc/nginx/sites-available/my.web.site
):这应该与此检查一起使用:
以防止 Rails 处理静态数据。
We used the similar technique as NoICE described, but i replaced the "hard-coded" directory containing all the files with the regular expression describing the folder containing the folders containing the files.
Sounds hard, yeah? Just take a look on these (
/etc/nginx/sites-available/my.web.site
):This should be used with this check:
to prevent the statics from Rails processing.
我通过本手册
https://mattbrictson.com/accelerated-rails-downloads
我的服务器发送文件路径
/private_upload/file/123/myfile.txt
,文件位于/data/myapp-data/private_upload/file/123/myfile.txt
I did by this manual
https://mattbrictson.com/accelerated-rails-downloads
my server sends file path
/private_upload/file/123/myfile.txt
, the file is in/data/myapp-data/private_upload/file/123/myfile.txt