【发布时间】:2018-01-31 22:57:04
【问题描述】:
我已经在我的 rails 4 项目中安装了 wicked_pdf。我让它在我的 Ubuntu 16 EC2 机器上的 nginx 和乘客下运行。
当我尝试在“生产”中生成 PDF 时,我收到以下错误:
ActionView::Template::Error (Permission denied @ dir_s_mkdir - /.../tmp/cache):
当然,如果我 chmod -R 777 我的 tmp 文件夹,它会起作用,但我不想以这种方式修复它。
在搜索时,我发现我应该将文件夹 chown 给 www-data 用户;我试过没有运气,也许生成PDF的过程应该有这个文件夹的权限?
提前致谢
编辑,添加痕迹:
App 17963 stdout: ***************WICKED***************
App 17963 stdout: Rendered posts/article.pdf.erb within layouts/article_pdf.html.erb (0.9ms)
App 17963 stdout: Completed 500 Internal Server Error in 34ms (ActiveRecord: 6.5ms)
App 17963 stdout:
App 17963 stdout: ActionView::Template::Error (Permission denied @ dir_s_mkdir - xxx/.../tmp/cache):
App 17963 stdout: 3: <head>
App 17963 stdout: 4: <title></title>
App 17963 stdout: 5: <%= stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" %>
App 17963 stdout: 6: <%= wicked_pdf_stylesheet_link_tag 'application' %>
App 17963 stdout: 7: <%= wicked_pdf_stylesheet_link_tag 'social' %>
App 17963 stdout: 8: <%= wicked_pdf_stylesheet_link_tag 'directories' %>
App 17963 stdout: 9: <%= wicked_pdf_stylesheet_link_tag 'home' %>
App 17963 stdout: app/views/layouts/article_pdf.html.erb:6:in `_app_views_layouts_article_pdf_html_erb__3815099653923299167_60691780'
App 17963 stdout: app/controllers/posts_controller.rb:167:in `block (2 levels) in article'
App 17963 stdout: app/controllers/posts_controller.rb:164:in `article'
App 17963 stdout:
App 17963 stdout:
App 17963 stdout: Processing by ErrorsController#internal_server_error as PDF
编辑 2: 每次我预编译我的资产并重新启动我的 nginx 服务器时都会出现此错误。似乎每次我预编译我的资产时,tmp 文件夹内容都会由 root 重新创建。
【问题讨论】:
-
可以添加堆栈跟踪吗?
-
@Tai,更新了..谢谢!
-
作为堆栈跟踪,我认为这个错误是在 Sprocket 编译资产时发生的。但是在生产中,资产应该被预编译,而不是在运行时编译。你能检查一下配置吗?另外,您可以尝试删除
tmp文件夹,以便Web 应用程序进程可以重新创建它以更正权限吗? -
感谢您的评论。我忘了提到这发生在我预编译我的资产之后。也许我配置错误? .每次我运行 rake assets:precompile 并重新启动我的 nginx 服务器时,都会出现此错误,我只能通过授予 tmp 文件夹可怕的权限来修复它。
-
如果您已经预编译了资产,则不应在运行时编译它们。是
assets.compiletrue还是false?我建议将其更改为false然后再试一次。
标签: ruby-on-rails nginx passenger wicked-pdf