与客运nginx的重写规则 [英] nginx rewrite rules with Passenger

查看:131
本文介绍了与客运nginx的重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用迁移乘客在两种情况下举办一个Rails应用程序从Apache到nginx的。该应用程序需要的请求,这是一个图像 - 如果在/系统/商标/ $ requestedimage的形象存在,那么它应该得到服务,或者如果需要它应该被允许打Rails应用程序生成它(在那里,然后缓存到/系统/徽标)。

I'm trying to migrate to nginx from Apache using Passenger in both instances to host a Rails app. The app takes a request, which is for an image- if the image exists at /system/logos/$requestedimage then it should get served, or it should be allowed to hit the Rails app to generate it if needed (where it is then cached to /system/logos).

在Apache的我用下面的:

In Apache I used the following:

RewriteCond %{DOCUMENT_ROOT}/system/logos/%{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1

这工作得很好。该资产。子是另一个子但与同根生,只是乘客禁用,专门设立的托管静态文件(到期明智)。

This worked fine. The assets. subdomain is another subdomain but with the same root, just Passenger disabled, specifically set up for hosting static files (expires-wise).

在nginx的我使用以下内容:

In nginx I am using the following:

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的是假设它是一个静态的资产所以不是将它传递给乘客。有没有一种方式,以便它击中的应用程序停止这种行为?

This doesn't work so well. At all, in fact. It never redirects to the cached path and it never hits the Rails app. It's like nginx is assuming it's a static asset so not passing it on to Passenger. Is there a way to stop this behaviour so it hits the app?

推荐答案

我的Rails应用程序在nginx的和乘客运行。我已经从默认的 /公 /公/系统/缓存/ 我的rails缓存目录。为了使它工作,我不得不插入到我的虚拟主机配置文件这样的:

My rails application is running on nginx and passenger. I have moved my rails cache directory from the default /public to /public/system/cache/. To make it work, I had to insert this into my vhost config file:

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_FILENAME 工作,但没有得到它的工作。与 $ URI 尝试,而不是,看看它的工作原理: - )

I remember that I too tried to make it work with $request_filename, but didn't get it to work. Try with $uri instead and see if it works :-)

这篇关于与客运nginx的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆