I am trying to deploy rails on jRuby using a .war file with the help of Warbler (Tomcat) and/or Torquebox 4 (Wildfly). The problem I face is that I don't know how to handle uploads with Carrierwave or Paperclip in this case. Ideally uploads should be stored outside the war, as it may be replaced with a newer version of the app anytime. I tried to create a symlink (uploads) in the public directory before I packaged the app as a war file to /home/username/uploads (permissions are set to 777) directory but that doesn't work (I get a 500 error).
在Warbler (Tomcat)和/或Torquebox 4 (Wildfly)的帮助下,我试图使用.war文件在jRuby上部署rails。我面临的问题是,在这种情况下,我不知道如何使用载波或回形针处理上传。理想情况下,上传应该存储在战争之外,因为它可以随时被更新的应用程序所替代。我尝试在公共目录中创建一个symlink (uploading),然后将应用程序打包为war文件到/home/ username/uploadingdirectory(权限设置为777)目录中(我得到了500个错误)。
Also how can I access the production.log after I deployed the war file? Or where should I place the logs?
以及如何访问产品。在我部署war文件之后进行日志记录?或者我应该把圆木放在哪里?
UPDATE I figured out how to config Carrierwave to store uploads outside the war file:
更新我找到了如何配置Carrierwave来存储war文件之外的上传:
if Rails.env.development?
CarrierWave.configure do |config|
config.root = "/Users/Username/username_uploads/uploads"
end
elsif Rails.env.production?
CarrierWave.configure do |config|
config.root = "/home/username/username_uploads/uploads"
end
end
Now Carrierwave uploads the files without a problem, but I get a 404 error when I try to view them. I tried to include a symlink inside the war file to the uploads folder but no success. I tried to create it before running warble war, and also after the app was deployed to Tomcat ( inside the app_name folder ).
现在Carrierwave上传的文件没有问题,但是当我试图查看它们时,我得到了一个404错误。我试图在war文件中包含一个符号链接到上传文件夹,但是没有成功。在运行warble war之前,以及部署到Tomcat(在app_name文件夹中)之后,我尝试创建它。
Any idea how to solve this?
你知道怎么解决这个问题吗?
UPDATE 2 I found a working solution here: Configure Symlinks for single directory in Tomcat
我在这里找到了一个有效的解决方案:为Tomcat中的单个目录配置符号链接
In short: cd into the exploded war directory ( you can find this under tomcat/webapps ) that tomcat created ( if the name of the uploaded war file is yourapp.war then the directory name will be yourapp in Tomcat 8 ). Create an uploads folder with sudo mkdir uploads
Create a mount point: sudo mount --bind /path/to/actual/upload/directory/uploads uploads
简而言之:将cd放到tomcat/webapps下的war目录中(如果上传的war文件的名称是yourapp)。war那么在Tomcat 8中,目录名将是您的应用程序。创建一个带有sudo mkdir上传的上传文件夹,创建一个挂载点:sudo mount—bind /path/to/实际/上传/目录/上传上传。
I haven't yet tested this with Wildfly, but I will later today or tomorrow. If I remember correctly it won't automatically explode war files by default.
我还没有用Wildfly进行测试,但是今天晚些时候或者明天我会进行测试。如果我没记错的话,默认情况下不会自动爆炸战争文件。
I would still like to know additional, simpler, different solutions for the problem though, and also opinions about the solution I found.
我仍然想知道这个问题的额外的、更简单的、不同的解决方案,以及对我找到的解决方案的意见。
4 个解决方案
#1
1
Just food for thought on a different approach...
这是另一种思考方式的食物……
Using a "cloud based" storage service would make the upload and serving of the assets problem go away, it would also make it simpler to scale the app should you ever need a second node,
使用“基于云”的存储服务将使资产的上传和服务问题消失,如果您需要第二个节点,它还将简化应用的扩展,
it would also reduce the need to scale the app because you would effectively delegate the large data operations which ruby traditionally handles badly to a different service
它还将减少对应用程序进行扩展的需求,因为您可以有效地将ruby传统处理糟糕的大型数据操作委托给不同的服务。
Amazon S3 is an obvious choice, but check out Riak too
Amazon S3是一个明显的选择,但是也可以看看Riak
#2
1
I think the problem you are experiencing with this solution:
我认为你现在遇到的问题是:
if Rails.env.development?
CarrierWave.configure do |config|
config.root = "/Users/Username/username_uploads/uploads"
end
elsif Rails.env.production?
CarrierWave.configure do |config|
config.root = "/home/username/username_uploads/uploads"
end
end
is that you are storing the images outside of the rails public folder, and therefore rails cannot serve them anymore. Carrierwave is uploading everything properly as you would expect it to do, and it creates links, relative to the storage dir. If you would use the default #{Rails.root}/public storage, rails would serve your images, as any content from public is served (also static html or other assets). As Rails doesn't serve these anymore it's up to you to serve them.
您正在rails公共文件夹之外存储映像,因此rails不能再为它们提供服务。Carrierwave按照您的期望上传了所有内容,并创建了与存储目录相关的链接。如果您将使用默认的#{Rails。根}/公共存储,rails将为您的图像服务,因为任何来自公共的内容都是服务的(也包括静态html或其他资产)。由于Rails不再提供这些服务,所以您可以为它们提供服务。
Maybe you can just directly serve them through Tomcat (as I have no expertise in Tomcat configuration you have to figure this out yourself). This would maybe even be faster, as the request surpass the rails stack.
也许您可以通过Tomcat直接服务它们(因为我在Tomcat配置方面没有专业知识,所以您必须自己解决这个问题)。这甚至可能更快,因为请求超过了rails堆栈。
#3
1
By default, Tomcat does not follow symbolic links (due security reasons). To enable this, you have to add the following inside the Host
tag in your server.xml
:
默认情况下,Tomcat不遵循符号链接(出于安全原因)。要启用此功能,您必须在服务器.xml的主机标记中添加以下内容:
<!-- Tomcat 7: -->
<Context allowLinking="true" />
<!-- Tomcat 8: -->
<Context>
<Resources allowLinking="true" />
</Context>
See the docs and the latest migration guide.
请参阅文档和最新的迁移指南。
#4
-1
If you could provide your logs it would be much easier to diagnose the problem (I take it this problem is only in production because you are asking about how to access that log?). Goto the rails app directory and look in log/production.log
these log levels are often lower so you may have to configure them to be more informative config/enviroments/prouction.rb
should have a config.log.level
this is probably set to info
set it to debug
for more verbose logging.
如果您可以提供您的日志,那么诊断问题就会容易得多(我认为这个问题只在生产中出现,因为您正在询问如何访问日志?)转到rails应用程序目录并查看日志/生产。记录这些日志级别通常较低,因此您可能需要将它们配置为更具信息性的配置/环境/构造。rb应该有config.log。这可能被设置为info,将其设置为debug,以便进行更详细的日志记录。
#1
1
Just food for thought on a different approach...
这是另一种思考方式的食物……
Using a "cloud based" storage service would make the upload and serving of the assets problem go away, it would also make it simpler to scale the app should you ever need a second node,
使用“基于云”的存储服务将使资产的上传和服务问题消失,如果您需要第二个节点,它还将简化应用的扩展,
it would also reduce the need to scale the app because you would effectively delegate the large data operations which ruby traditionally handles badly to a different service
它还将减少对应用程序进行扩展的需求,因为您可以有效地将ruby传统处理糟糕的大型数据操作委托给不同的服务。
Amazon S3 is an obvious choice, but check out Riak too
Amazon S3是一个明显的选择,但是也可以看看Riak
#2
1
I think the problem you are experiencing with this solution:
我认为你现在遇到的问题是:
if Rails.env.development?
CarrierWave.configure do |config|
config.root = "/Users/Username/username_uploads/uploads"
end
elsif Rails.env.production?
CarrierWave.configure do |config|
config.root = "/home/username/username_uploads/uploads"
end
end
is that you are storing the images outside of the rails public folder, and therefore rails cannot serve them anymore. Carrierwave is uploading everything properly as you would expect it to do, and it creates links, relative to the storage dir. If you would use the default #{Rails.root}/public storage, rails would serve your images, as any content from public is served (also static html or other assets). As Rails doesn't serve these anymore it's up to you to serve them.
您正在rails公共文件夹之外存储映像,因此rails不能再为它们提供服务。Carrierwave按照您的期望上传了所有内容,并创建了与存储目录相关的链接。如果您将使用默认的#{Rails。根}/公共存储,rails将为您的图像服务,因为任何来自公共的内容都是服务的(也包括静态html或其他资产)。由于Rails不再提供这些服务,所以您可以为它们提供服务。
Maybe you can just directly serve them through Tomcat (as I have no expertise in Tomcat configuration you have to figure this out yourself). This would maybe even be faster, as the request surpass the rails stack.
也许您可以通过Tomcat直接服务它们(因为我在Tomcat配置方面没有专业知识,所以您必须自己解决这个问题)。这甚至可能更快,因为请求超过了rails堆栈。
#3
1
By default, Tomcat does not follow symbolic links (due security reasons). To enable this, you have to add the following inside the Host
tag in your server.xml
:
默认情况下,Tomcat不遵循符号链接(出于安全原因)。要启用此功能,您必须在服务器.xml的主机标记中添加以下内容:
<!-- Tomcat 7: -->
<Context allowLinking="true" />
<!-- Tomcat 8: -->
<Context>
<Resources allowLinking="true" />
</Context>
See the docs and the latest migration guide.
请参阅文档和最新的迁移指南。
#4
-1
If you could provide your logs it would be much easier to diagnose the problem (I take it this problem is only in production because you are asking about how to access that log?). Goto the rails app directory and look in log/production.log
these log levels are often lower so you may have to configure them to be more informative config/enviroments/prouction.rb
should have a config.log.level
this is probably set to info
set it to debug
for more verbose logging.
如果您可以提供您的日志,那么诊断问题就会容易得多(我认为这个问题只在生产中出现,因为您正在询问如何访问日志?)转到rails应用程序目录并查看日志/生产。记录这些日志级别通常较低,因此您可能需要将它们配置为更具信息性的配置/环境/构造。rb应该有config.log。这可能被设置为info,将其设置为debug,以便进行更详细的日志记录。