Ruby on rails nginx与乘客一起重写规则

Ruby on rails nginx与乘客一起重写规则,ruby-on-rails,ruby,apache,nginx,passenger,Ruby On Rails,Ruby,Apache,Nginx,Passenger,我正在尝试从Apache迁移到nginx,在这两个实例中都使用Passenger来托管Rails应用程序。应用程序接受一个请求,该请求针对一个图像-如果图像存在于/system/logos/$requestedimage,那么它应该得到服务,或者如果需要,应该允许它点击Rails应用程序生成它(然后缓存到/system/logos) 在Apache中,我使用了以下内容: RewriteCond %{DOCUMENT_ROOT}/system/logos/%{REQUEST_FILENAME} -

我正在尝试从Apache迁移到nginx,在这两个实例中都使用Passenger来托管Rails应用程序。应用程序接受一个请求,该请求针对一个图像-如果图像存在于/system/logos/$requestedimage,那么它应该得到服务,或者如果需要,应该允许它点击Rails应用程序生成它(然后缓存到/system/logos)

在Apache中,我使用了以下内容:

RewriteCond %{DOCUMENT_ROOT}/system/logos/%{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1
server {
  listen 80;
  passenger_enabled on;
  server_name  clg.eve-metrics.com www.clg.eve-metrics.com;
  root /opt/www/clg/current/public;
  gzip             on;
  gzip_min_length  1000;
  gzip_proxied     expired no-cache no-store private auth;
  gzip_types       text/plain application/xml text/css application/javascript;
  gzip_disable     msie6;
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
  }
  if (-f $document_root/system/logos$request_filename) { 
    rewrite ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1 break;
  }
}
这很有效。资产。子域是另一个子域,但具有相同的根,只是乘客禁用,专门设置为托管静态文件(过期)

在nginx中,我使用以下内容:

RewriteCond %{DOCUMENT_ROOT}/system/logos/%{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1
server {
  listen 80;
  passenger_enabled on;
  server_name  clg.eve-metrics.com www.clg.eve-metrics.com;
  root /opt/www/clg/current/public;
  gzip             on;
  gzip_min_length  1000;
  gzip_proxied     expired no-cache no-store private auth;
  gzip_types       text/plain application/xml text/css application/javascript;
  gzip_disable     msie6;
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
  }
  if (-f $document_root/system/logos$request_filename) { 
    rewrite ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1 break;
  }
}

这不太好用。事实上,一点也不。它从不重定向到缓存路径,也从不访问Rails应用程序。就像nginx假设它是一个静态资产,所以不会将其传递给乘客。有没有办法阻止这种行为,使其命中应用程序?

我的rails应用程序正在nginx和passenger上运行。我已将rails缓存目录从默认的
/public
移动到
/public/system/cache/
。为了使其正常工作,我必须将其插入vhost配置文件:

if (-f $document_root/system/cache/$uri/index.html) {
  rewrite (.*) /system/cache/$1/index.html break;
}

if (-f $document_root/system/cache/$uri.html) {
  rewrite (.*) /system/cache/$1.html break;
}

我记得我也曾试图让它与
$request\u filename
一起工作,但没有成功。请改用
$uri
试试,看看它是否有效:-)

詹姆斯,请试试这个配置文件 请注意此位置配置:

  location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico)(\?[0-9]+)?$ {
      access_log off;
      expires max;
      add_header Cache-Control public;
  }

如果您拥有正确的权限,passenger不会让Rails管理您的资产文件(用户运行的nginx应该拥有直接访问文件的权限)

我也遇到过同样的问题,而且我是nginx的新手,所以这一点非常有效。谢谢。nginx.conf里面是什么指令?