在使用Pow和Nginx的开发中,文件上载不适用于Rails 4

罗希米什拉

我正在使用Pow和Nginx在开发中提供我的Rails 4应用程序。一个简单的文件上传返回500错误,并且请求未到达Rails控制器。我认为是这种情况,因为在Rails日志中没有提及该请求。没有提到错误,我不确定这里出了什么问题。

我从上载Ajax文件开始,但是用一个也不起作用的简单表格代替了它。

试过这个

原始上传按钮

然后去这个

简单上传表格

当前avatar.html.erb

<%= form_for @user, html: { multipart: true }, method: "post", url: '/settings/avatar/update', class: "", id: "update_avatar" do |f| %>
  <%= f.file_field :avatar, class: 'js-upload-photo-button js-change-avatar-btn', accept: 'image/png,image/gif,image/jpeg,image/jpg' %>
    <%= f.submit "Upload" %>
<% end %>

在Chrome中请求标题

完整请求标头

扩展的请求标头部分

扩展的请求标头部分

nginx.log

127.0.0.1 - - [01/Feb/2014:11:28:26 +0530] "POST /settings/avatar/update HTTP/1.1" 500 643 "https://allotrop.dev/settings/avatar" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36"

战俘access.log

[Sat Feb 01 2014 11:28:26 GMT+0530 (IST)] INFO [127.0.0.1] GET allotrop.dev /500.html

There are other questions here about Rails returning 500 error with no mention in log rails 500 error no production log entry , Rails 3.2.13, 500 error in development with no log and How to properly diagnose a 500 error (Rails, Passenger, Nginx, Postgres)

But these are one-off errors and do not seem related to the problem I am facing. It would be great if anyone can point me in the right direction.

Update 1

Relevant line from routes.rb

post '/settings/avatar/update', to: 'settings#update_avatar'

Update 2

Found my nginx error log. BTW, if you are using Homebrew, it is at /usr/local/Cellar/nginx/1.4.0/logs/error.log

nginx/error.log

2014/02/01 13:05:54 [crit] 8787#0: *85813 open() "/usr/local/var/run/nginx/client_body_temp/0000000010" failed (13: Permission denied), client: 127.0.0.1, server: *.dev, request: "POST /settings/avatar/update HTTP/1.1", host: "allotrop.dev", referrer: "https://allotrop.dev/settings/avatar"

rohitmishra

The problem is not with Rails but with Nginx which is pretty evident from the nginx error.log. This question helped me understand what I was dealing with - Rails 3 + carrierwave + nginx = permission denied.

Nginx uses the client_body_temp_path directive to specify the location where it will temporarily store the uploaded files from the user request. Homebrew had set it by default to /usr/local/var/run/nginx. This folder also contains fastcgi_temp, proxy_temp, scgi_temp and uwsgi_temp for me. Nginx worker processes run with user nobody and they were not able to access these folders. I chowned all these folders to the nobody user, but that did not help.

Finally, I did

client_body_temp_path /tmp/nginx/; inside the HTTP module of my nginx.conf to make it work.

Doing a ls -l shows

drwx------ 2 nobody wheel 68 Feb 1 14:44 nginx

I am not sure why this worked inside /tmp and not inside the original /var/run/nginx. I belive I will face similar issue when I use other temp folders or in production. Will update this thread if and when that happens.

我建议将其他相关日志符号链接到/log您的Rails应用程序目录,例如nginx访问和错误日​​志,pow访问和应用程序日志当您遇到棘手的错误时,它有助于查找其中一种错误。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

remote:true选项不适用于rails 4中的文件字段

AWS凭证不适用于Rails 4和Mongoid中的Paperclip图像上传

Rails 4 JSON属性类型不适用于Postgres

Rails 4强参数不适用于多态关联

Rails 4:模型验证不适用于创建

文件上传不适用于PrimeFaces 4.0,PrettyFaces 3.3.3和GlassFish 4

蒸气不适用于xcode 9和swift 4

FFMPEG不适用于mp4和stdout

MinDate和MaxDate在Ionic 4中不适用于本机日期选择器

循环不适用于使用python和beautifulsoup4抓取数据

更改事件不适用于角度4中的跨度

使用策略不适用于AzureRmWebAppDeployment @ 4

或条件不适用于滑轨4

Datepicker 不适用于 bootstrap 4

Webpack 4文件加载器适用于字体文件,但不适用于图像文件

Gremlin 查询适用于 TinkerGraph、JanusGraph 和 Neo4j,但不适用于 DSE Graph 6.8.1

Rails 4:创建记录的链接标记不适用于强参数

Simple Rails 4 ActionController :: Live示例不适用于Apache + Passenger

Rails 4-Devise_scope,root用户不适用于多种类型的用户(STI)

使用0.9.5.RC4的Karate.toMap()适用于方案,但不适用于方案大纲

Codeigniter4 htaccess 文件不适用于所有选项 - 索引

钥匙串类不适用于iPhone 4s / 5和iPad

授权属性不适用于IdentityServer4和.NET Core 3.1

导航栏下拉菜单不适用于Angular和Bootstrap 4

子模型获取器和设置器不适用于角度2/4

重写模式不适用于virtualhost和symfony4

从html提取文本和链接不适用于bs4

下拉按钮不适用于bootstrap 4

Angular 4 不适用于 IE 9