简体   繁体   English

Rails Production Server上禁止的资产

[英]Assets Forbidden on Rails Production Server

I am attempting to deploy a rails app onto an Apache server. 我正在尝试将Rails应用程序部署到Apache服务器上。 I am attempting to access jquery in the app's assets folder with: 我正在尝试通过以下方式访问应用程序资产文件夹中的jquery:

<script src="/assets/jquery.js" type="text/javascript"></script>

I am also attempting to load a custom script with a javascript_include_tag. 我还尝试使用javascript_include_tag加载自定义脚本。 As I look in the javascript console of my web browser, I see that the server responds with a 403 forbidden error code when trying to access these scripts. 当我在Web浏览器的javascript控制台中查看时,我发现尝试访问这些脚本时服务器以403禁止的错误代码响应。

I attempted to chmod 775 my /var/www//public/assets folder but this did not resolve the problem. 我试图对我的/ var / www // public / assets文件夹执行chmod 775,但这不能解决问题。 I have tried both running rake assets:precompile and changing the production.rb to serve static files and setting config.assets.compile to true. 我已经尝试了运行rake asset:precompile和更改production.rb以提供静态文件并将config.assets.compile设置为true。

确保在/config/environments/production.rb中启用了紧急加载。

I'm not sure why this works, but I ran 我不确定为什么会这样,但是我跑了

rm -rf public/assets

in my application directory and changed my production.rb so that 在我的应用程序目录中,并更改了production.rb,以便

config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compile = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM