简体   繁体   English

Ruby on Rails应用程序在生产环境中找不到样式表和JavaScript?

[英]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使用passengernginx部署了Ruby on Rails应用程序,但是在我的应用程序中找不到cssjs文件。

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 . 但是我对此发表评论,它仍然找不到jscss 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.

相关问题 Ruby on Rails应用程序无法在生产环境中找到JavaScript运行时(与passenger和nginx一起部署)? - Ruby on rails application cannot find a JavaScript runtime in production environment(deploy with passenger and nginx)? 样式表缺失-Ruby On Rails应用程序 - Stylesheets Missing - Ruby On Rails Application 生产环境中的Rails和Javascript - Rails and Javascript in production environment Heroku生产环境中不存在Ruby on Rails应用程序页面 - Ruby on Rails Application Page Does Not Exist in Heroku Production Environment Ruby on Rails-/ stylesheet目录中的样式表而不是/ assets中的样式表,生产中没有指纹 - Ruby on Rails - Stylesheets in /stylesheet directory and not in /assets, no fingerprint in production 为什么无法在生产环境访问 rails 应用程序? - Why can't access rails application on production environment? 有没有办法在类似于 rails.env 的 Ruby 应用程序中找到当前环境? - Is there a way to find current environment in a Ruby application similar to rails.env? Ruby on Rails条件样式表 - Ruby on Rails conditional stylesheets 生产环境中的Solr初始化失败,并且在轨道上有红宝石 - Solr Initialization failure in production environment with ruby on rails Ruby on Rails:生产环境的详细错误日志 - Ruby on Rails : Detailed error logs for a production environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM