[英]Ruby on Rails application can not find stylesheets and javascript in production environment?
I deploy a Ruby on Rails
application in ubuntu
with passenger
and nginx
, but it cannot find the css
and js
files in my application. 我在ubuntu
使用passenger
和nginx
部署了Ruby on Rails
应用程序,但是在我的应用程序中找不到css
和js
文件。
Here is the error message: 这是错误消息:
open() "/var/nginx/blog/public/stylesheets/application.css" failed (2: No such file or directory)
In fact, /var/nginx/blog/public/stylesheets/application.css
don't exist actually, my js
files is in /var/nginx/blog/app/assets/javascripts/
, my css
files is in /var/nginx/blog/app/assets/stylesheets
实际上, /var/nginx/blog/app/assets/javascripts/
/var/nginx/blog/public/stylesheets/application.css
实际上不存在,我的js
文件在/var/nginx/blog/app/assets/javascripts/
,我的css
文件在/var/nginx/blog/app/assets/stylesheets
In my nginx.conf
, I write this: 在我的nginx.conf
,我这样写:
location ~ ^/(assets|images|javascripts|stylesheets|system)/ {
expires max;
add_header Cache-Control public;
}
It seems that this is the place which is wrong! 好像这里是错的地方! But I comment this, it still cannot find js
and css
. 但是我对此发表评论,它仍然找不到js
和css
。 how do I config to get these files? 如何配置以获取这些文件?
Maybe you should put your assets in public/
folder. 也许您应该将资产放在public/
文件夹中。 Do you try precompile the assets? 您是否尝试预编译资产?
rake assets:precompile
You should to run RAILS_ENV=production bundle exec rake assets:precompile
on remote server where you deploying. 您应该在要部署的远程服务器上运行RAILS_ENV=production bundle exec rake assets:precompile
。
assets:precompile
rake task compressing and minimizing your assets for fast and reliable high-load production usage. assets:precompile
rake任务,压缩并最小化您的资产,以快速可靠地进行高负荷生产。 Do not need to run this task on your development enviroment. 无需在您的开发环境上运行此任务。
Would be better if you can show your deploy script. 如果可以显示您的部署脚本,那就更好了。 But most of deployment solutions like capistrano automaticaly doing this things right. 但是大多数部署解决方案(如capistrano)会自动执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.