生产环境中的rack-zippy和option -d不提供静态资产 [英] rack-zippy and option -d in production env doesn't serve static assets

查看:83
本文介绍了生产环境中的rack-zippy和option -d不提供静态资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有一个很奇怪的问题.我在Rails应用程序中使用rack-zippy gem,并且如果在没有预编译资产的情况下在development环境中启动它,则它就像一个魅力.使用-d参数且不使用.

I've a really weird problem here. I'm using the rack-zippy gem in my rails application and if I start it in development environment without pre-compiled assets it works like a charm. With the -d param and without.

在生产模式(相同的机器,相同的项目,相同的目录,相同的gem)中,它也可以工作.但是,如果我使用-d参数(bundle exec rails server -d)启动它以守护服务器,则将不提供预编译的资产.可以用thinwebrick重现,而不能用unicorn重现.

In production mode (same machine, same project, same directory, same gems) it works too. But if I start it with the -d param (bundle exec rails server -d) to daemonize the server, the pre-compiled assets will not be served. Can reproduce that with thin and webrick but NOT with unicorn.

日志显示:

ActionController::RoutingError (No route matches [GET]
    "/assets/application-b9b75968aed42128cfd75fb78df1e4d1.js"):

但是:

$ l public/assets/application-b9b75968aed42128cfd75fb78df1e4d1.js
-rw-r--r-- 1 public/assets/application-b9b75968aed42128cfd75fb78df1e4d1.js

在config/environments/production.rb中:

From config/environments/production.rb:

config.serve_static_assets = true

在config/application.rb中:

From config/application.rb:

config.middleware.swap(ActionDispatch::Static, Rack::Zippy::AssetServer)

并且:

$ rake middleware            
use Rack::Sendfile
use Rack::Zippy::AssetServer
(...)

我现在有些困惑.有什么想法吗?

I'm somewhat confused right now. Any ideas?

推荐答案

好吧,我从未遇到过,但是我会告诉您我的直觉,也许您可​​以在此取得一些进展. (感谢您在Github问题跟踪器上报告该问题.

Ouch, I've never encountered this, but I'll tell you my gut feel and maybe you can get somewhere with this. (Thanks for reporting it on the Github issue tracker).

所以独角兽还可以,但是瘦瘦的和webrick不好,mmmm.

So unicorn is OK, but thin and webrick are not, mmmm.

我的 guess 是守护程序进程用于Thin和Webrick的工作目录不是Rails.root.您可能想尝试在rack-zippy中调试此行,以查看正在搜索资产文件的路径:

My guess is that the working directory used by the daemon process for thin and webrick is not Rails.root. You might want to try debugging this line in rack-zippy to see what the path is being searched for the asset file: https://github.com/eliotsykes/rack-zippy/blob/master/lib/rack-zippy.rb#L87

从1.1.0版开始(如果您使用的是最新的Gem,则可能正在使用)的zip-zippy将所有无法找到文件的请求传递给其余的中间件堆栈.

rack-zippy since version 1.1.0 (which you're probably using if you're using the latest Gem) passes all requests it can't find a file for on to the remaining middleware stack.

在开发+守护程序模式下,rack-zippy会将请求传递到资产管道上,因此我认为我们可以假定资产管道在守护程序模式下没有问题.

In development+daemon mode, rack-zippy will be passing the request onto the asset pipeline, so I think we can assume that the asset pipeline has no problems with daemon mode.

在生产+守护程序模式下,资产管道可能已禁用(如您所愿),如果找不到资产文件,rack-zippy将向前传递请求(如果工作目录不是Rails.root),然后其余的中间件将为您显示路由错误.

In production+daemon mode, the asset pipeline is probably disabled (as you'd want), and rack-zippy will be passing the request onward if it can't find the asset file (which is probably the case if the working directory is not Rails.root), and then the remaining middleware will give you the routing error you see.

如果您在生产中启用了资产管道(非常不推荐),那么我希望路由错误会消失,并且zip-zippy不会做任何有用的事情.

If you enabled the asset pipeline in production (very much not recommended), then I would expect the routing error would disappear, and rack-zippy would not be doing anything useful.

对不起,我没有更坚定的理由要继续下去.

Sorry I don't have anything more solid for you to go on.

这篇关于生产环境中的rack-zippy和option -d不提供静态资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆