小编sis*_*ssy的帖子

Apache和logrotate配置

上周我在我的服务器上发现了一个问题,因为磁盘使用率是100%,我发现apache创建了一个60GB的巨大error.log文件.然后我将LogLevel更改为emerg,但是在一周之后它又是1.3GB,这肯定是太多了.此外,我有一个6MB的access.log和167MB的other_vhosts_access.log.所以我发现问题可能是logrotate无法正常工作.实际上,日志的gzip文件有一个非常旧的日期(2月23日).所以我首先尝试更改apache2的logrotate文件的配置,为文件添加最大大小,现在看起来像这样:

/var/log/apache2/*.log {
    weekly
    size 500M
    missingok
    rotate 20
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
                if /etc/init.d/apache2 status > /dev/null ; then \
                    /etc/init.d/apache2 reload > /dev/null; \
                fi;
    endscript
    prerotate
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
            run-parts /etc/logrotate.d/httpd-prerotate; \
        fi; \
    endscript
}
Run Code Online (Sandbox Code Playgroud)

在此之后,我尝试手动强制logrotate运行apache的特定配置

logrotate -f /etc/logrotate.d/apache2
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

error: skipping "/var/log/apache2/access.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to …
Run Code Online (Sandbox Code Playgroud)

apache ubuntu apache2 logrotate

30
推荐指数
3
解决办法
4万
查看次数

Rails + X-Sendfile为Ipad提供大型视频

我有一个应用程序服务大(几百MB)的视频文件,它在桌面浏览器上完美运行,在Apache上使用Rails + X-Sendfile.一个重要的要求是这些视频必须是私有的,并且只对已登录的用户可见,因此这就是我使用Rails为其提供服务的原因.

一切都与其他设备完美配合.我以这种方式提供视频:

response.headers["X-Sendfile"]=  filename
send_file filename, :disposition => :inline, :stream => true, :x_sendfile => true
Run Code Online (Sandbox Code Playgroud)

但是Ipad的请求需要字节范围头.解决方案(不能完美运行)是这样的:

size = File.size(filename)
bytes = Rack::Utils.byte_ranges(request.headers, size)[0]
offset = bytes.begin
length = bytes.end  - bytes.begin

response.header["Accept-Ranges"]=  "bytes"
response.header["Content-Range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}"

send_data IO.binread(filename,length, offset), :type => "video/mp4", :stream => true, :disposition => 'inline', :file_name => filename 
Run Code Online (Sandbox Code Playgroud)

有了这个解决方案,我遇到了大于50mb视频的问题,而且更重要的是,我给了rails一个不应该有的责任.通过x-sendfile模块处理流的繁重负载应该是apache.但我不知道如何.该send_data方法没有x-sendfile参数,涉及send_file方法的解决方案不起作用.

我发现这两个问题与我的相似,但它们不起作用:rails media file stream通过send_data或send_file方法接受字节范围请求,通过rails向Ipad提供mp4文件的正确方法是什么?

关于发生了什么的任何线索?我几周以来一直在努力,我需要让它发挥作用.欢迎其他可行的解决方案.

ruby-on-rails x-sendfile video-streaming ipad ruby-on-rails-4

15
推荐指数
1
解决办法
981
查看次数

Rails4:image_url不在scss中生成摘要

我无法理解为什么我的css文件没有使用辅助方法将摘要附加到我的资产 image_url

我的资产已正确预先推荐,文件确实包含摘要.我也可以手动访问它们(使用消化的URL).最奇怪的是,它一开始就有效.

这是我的配置:

  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.digest = true
  config.assets.version = '1.0'
  config.serve_static_assets = false #also tried true
Run Code Online (Sandbox Code Playgroud)

这是我的application.css:*= require_tree.

这是common.scss文件,用于包含图像:

body{
    background: image_url('bg.jpg');
    font-family: 'Lato', sans-serif;
    overflow-x: hidden;
}
Run Code Online (Sandbox Code Playgroud)

图像以及样式表位于资产/图像和资产/样式表中的子文件夹中.

在这里我的宝石:

gem 'rails', '4.0.0'
gem 'sass-rails', '~> 4.0.0'
Run Code Online (Sandbox Code Playgroud)

我正在使用capistrano部署,但我不认为这是一个与capistrano相关的问题,资产编制得很好.

编辑 到目前为止我(尝试失败)的尝试:

image-url('image.jpg'); -> http://www.mydomain.it/images/image.jpg
image_url('image.jpg');    -> same as above
url(image-path('header.jpg'));  -> http://www.mydomain.it/images/image.jpg
asset-url('image.jpg', image); -> http://www.mydomain.it/image.jpg
Run Code Online (Sandbox Code Playgroud)

问题仍然存在:资产已编译但未经摘要请求.

编辑

关注这个问题Rails 4 image-path,image-url和asset-url不再适用于SCSS文件我移动了我的资产并使用asset-url的组合并将我的资产放在/ public文件夹中,背景图像正常工作,甚至虽然问题仍然存在,因为应用程序没有使用图像的带时间戳的版本.所以只有一个(不是好的,也不是坏的)解决方法.

ruby-on-rails asset-pipeline ruby-on-rails-4

9
推荐指数
1
解决办法
5399
查看次数

Rails4:如何限制流媒体视频文件的访问?

我想在我的页面中放置一些html5视频,但只能向登录的用户提供对此视频的访问权限(因此,未登录的用户必须看不到视频,如果他们有网址的话):

<video width="320" height="240" controls>
  <source src="/video.mp4" type="video/mp4">
  <source src="/video.m4v" type="video/m4v">
Your browser does not support the video tag.
</video>
Run Code Online (Sandbox Code Playgroud)

我在我的行动中尝试了类似的东西(使用前过滤器进行访问限制):

  def video
    respond_to do |format|
      format.m4v{
        send_data File.join([Rails.root, "public", "videos", "sample.m4v"]), type: 'video/m4v', disposition: :inline
      }
      format.mp4{
        send_data File.join([Rails.root, "public", "videos", "sample.mp4"]), type: 'video/mp4', disposition: :inline
      }
    end
  end
Run Code Online (Sandbox Code Playgroud)

但这是将文件作为附件发送,而不仅仅是提供它.

可能吗?如果是的话,怎么办呢?

谢谢

assets ruby-on-rails video-streaming html5-video ruby-on-rails-4

5
推荐指数
1
解决办法
1366
查看次数

ASCII-8BIT 中的 Rails 编码

我知道这已经被问过好几次了,但对我来说发生了一些奇怪的事情:

我有一个索引视图,其中渲染某些字符(带重音的字母)会导致 Rails 引发异常

incompatible character encodings: ASCII-8BIT and UTF-8
Run Code Online (Sandbox Code Playgroud)

所以我检查了我的字符串编码,这实际上到处都是 ASCII-8BIT,即使我在 application.rb 中将正确的编码设置为 UTF-8

config.encoding = "utf-8"
Run Code Online (Sandbox Code Playgroud)

在我的 environment.rb 中

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
Run Code Online (Sandbox Code Playgroud)

在我的数据库中它出现:

character_set_database = utf-8
Run Code Online (Sandbox Code Playgroud)

正如一些指南中所建议的那样。

字符串与 textarea 字段一起插入,并且不会连接到任何其他已插入的字符串。

奇怪的是:

  • 这仅发生在索引视图中,而这不会发生在节目中(相同资源)
  • 这只发生在这个模型(这是一封电子邮件,有主题和正文,但这不应该影响任何事情)
  • 在我的开发环境中一切顺利str.force_encoding('utf-8'),而在我的生产环境中这不起作用。(开发我使用 Ruby 2.0.0,生产 Ruby 2.1.0,Rails4 和 MySql)
  • 设置文件视图# encoding utf-8也不起作用
  • 尝试str.force_encoding('ascii-8bit').encode('utf-8')Encoding::UndefinedConversionError "\xC3" from ASCII-8BIT to UTF-8哪个是à,而使用body.force_encoding('ascii-8bit').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?'),则用 ? 替换所有带重音str.force_encoding('iso-8859-1').encode('utf-8')的字符,而显然会生成错误的字符 (a …

encoding ruby-on-rails utf-8 ruby-on-rails-4 ruby-2.1

5
推荐指数
1
解决办法
5512
查看次数