验证码图像在我的生产环境中不起作用,但开发正常
我在本地计算机(OSX 10.6.6,Rails3.0.1,WEBrick)
中编写了一个 Rails 应用程序。简单的验证码效果很好。当我将应用程序推送到我的网络服务器(Centos5.5,Rails 3.0.1,Phusion Passenger版本3.0.2)
时,没有发现错误,但图像不显示在网站中。
我注意到 /tmp
有一些文件,例如 simple_captcha20110324-19769-1bf4hah.jpg
。我在我的服务器中打开它,图像是验证码图像。所以我认为验证码生成是有效的,但在生产环境中出现了问题。我跟踪该过程并发现ioctl(27, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffc3fad550) = -1 ENOTTY(不适合设备的ioctl)。您有什么建议吗?
strace 信息:
...
stat("/tmp/simple_captcha20110324-3073-14fnzd6.jpg", {st_mode=S_IFREG|0600, st_size=1808, ...}) = 0
stat("/tmp/simple_captcha20110324-3073-14fnzd6.jpg", {st_mode=S_IFREG|0600, st_size=1808, ...}) = 0
geteuid() = 500
getegid() = 500
getuid() = 500
getgid() = 500
access("/tmp/simple_captcha20110324-3073-14fnzd6.jpg", R_OK) = 0
open("/tmp/simple_captcha20110324-3073-14fnzd6.jpg", O_RDONLY) = 27
ioctl(27, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffc3fad550) = -1 ENOTTY (Inappropriate ioctl for device)
brk(0x63b0000) = 0x63b0000
write(3, "\n\nStarted GET \"/simple_captcha/e"..., 133) = 133
clock_gettime(CLOCK_REALTIME, {1300937319, 188732000}) = 0
writev(11, [{"Status: ", 8}, {"200", 3}, {"\r\n", 2}, {"X-Powered-By: ", 14}, {"Phusion Passenger (mod_rails/mod"..., 44}, {"\r\n", 2}, {"Content-Disposition", 19}, {": ", 2}, {"inline; filename=\"simple_captcha"..., 37}, {"\r\n", 2}, {"Content-Transfer-Encoding", 25}, {": ", 2}, {"binary", 6}, {"\r\n", 2}, {"Content-Type", 12}, {": ", 2}, {"image/jpeg", 10}, {"\r\n", 2}, {"Cache-Control", 13}, {": ", 2}, {"private", 7}, {"\r\n", 2}, {"X-UA-Compatible", 15}, {": ", 2}, {"IE=Edge,chrome=1", 16}, {"\r\n", 2}, {"Set-Cookie", 10}, {": ", 2}, {"_newuser_session=BAh7CEkiD3Nlc3N"..., 275}, {"\r\n", 2}, {"X-Sendfile", 10}, {": ", 2}, ...], 39) = 623
shutdown(11, 1 /* send */) = 0
close(11) = 0
...
更新:
我认为 https://github.com/galetahub/simple-captcha也许吧。我选择了这个分支 https://github.com/kares/simple_captcha 所有环境工作正常!
I write a rails app in my local machine(OSX 10.6.6,Rails3.0.1,WEBrick)
. Simple-captcha works fine. When I push the app to my web server (Centos5.5,Rails 3.0.1,Phusion Passenger version 3.0.2)
no error is found but the image does not display in the site.
I notice /tmp
has some files like simple_captcha20110324-19769-1bf4hah.jpg
. I open it in my server, the image is captcha image. So I think the captcha generate is working, but something wrong in the production environment. I trace the process and found ioctl(27, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffc3fad550) = -1 ENOTTY (Inappropriate ioctl for device)
. Do you have any suggestions?
strace info:
...
stat("/tmp/simple_captcha20110324-3073-14fnzd6.jpg", {st_mode=S_IFREG|0600, st_size=1808, ...}) = 0
stat("/tmp/simple_captcha20110324-3073-14fnzd6.jpg", {st_mode=S_IFREG|0600, st_size=1808, ...}) = 0
geteuid() = 500
getegid() = 500
getuid() = 500
getgid() = 500
access("/tmp/simple_captcha20110324-3073-14fnzd6.jpg", R_OK) = 0
open("/tmp/simple_captcha20110324-3073-14fnzd6.jpg", O_RDONLY) = 27
ioctl(27, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffc3fad550) = -1 ENOTTY (Inappropriate ioctl for device)
brk(0x63b0000) = 0x63b0000
write(3, "\n\nStarted GET \"/simple_captcha/e"..., 133) = 133
clock_gettime(CLOCK_REALTIME, {1300937319, 188732000}) = 0
writev(11, [{"Status: ", 8}, {"200", 3}, {"\r\n", 2}, {"X-Powered-By: ", 14}, {"Phusion Passenger (mod_rails/mod"..., 44}, {"\r\n", 2}, {"Content-Disposition", 19}, {": ", 2}, {"inline; filename=\"simple_captcha"..., 37}, {"\r\n", 2}, {"Content-Transfer-Encoding", 25}, {": ", 2}, {"binary", 6}, {"\r\n", 2}, {"Content-Type", 12}, {": ", 2}, {"image/jpeg", 10}, {"\r\n", 2}, {"Cache-Control", 13}, {": ", 2}, {"private", 7}, {"\r\n", 2}, {"X-UA-Compatible", 15}, {": ", 2}, {"IE=Edge,chrome=1", 16}, {"\r\n", 2}, {"Set-Cookie", 10}, {": ", 2}, {"_newuser_session=BAh7CEkiD3Nlc3N"..., 275}, {"\r\n", 2}, {"X-Sendfile", 10}, {": ", 2}, ...], 39) = 623
shutdown(11, 1 /* send */) = 0
close(11) = 0
...
UPDATE:
I think some bug in https://github.com/galetahub/simple-captcha maybe. I chose this branch https://github.com/kares/simple_captcha all env work fine!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
https://github.com/galetahub/simple-captcha 使用 send_file (来自 Rails Streaming API)流式传输验证码图像。您是否在 apache 配置中启用了 mod-xsendfile?
https://github.com/galetahub/simple-captcha uses send_file (from rails streaming api) to stream the captcha image. Did you enable mod-xsendfile in your apache configuration?
您应该尝试在 config/environments/production.rb 文件中设置 config.serve_static_assets = true 。
默认情况下,出于性能原因,rails 在生产模式下不提供静态内容。您的网络服务器应该配置为执行此操作。
You should try setting config.serve_static_assets = true in your config/environments/production.rb file.
By default, rails does not serve static content in production mode, for performance reasons. Your webserver should be configured to do that.
如果我记得验证码对于开发和生产环境有不同的密钥,您已经检查过了吗?
if I remember captcha has different keys for development and production environments, have you already checked it out?