nginx rewrite rules with Passenger

99封情书 提交于 2019-12-03 18:05:00

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;
}

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 :-)

James, please try this configuration file https://gist.github.com/711913 and pay attention on this location config:

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

passenger won't let Rails to manage your assets files if you have right permissions (user run nginx should has permissions to access to file directly)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!