【问题标题】:Broken images/css in production mode with Rails 4使用 Rails 4 在生产模式下损坏的图像/css
【发布时间】:2015-10-23 15:14:36
【问题描述】:

我正在生产模式下运行 Rails 4 应用程序...在 Windows 8.1... 由于某种原因,您在生产模式下损坏了图像和 css。由于 Windows 中没有Passenger gem,我必须使用 Apache 配置重定向或反向代理到 Thin

<VirtualHost *:8888>
    ServerAdmin webmaster@example.com
    ServerName Depot
    #ServerAlias 

    DocumentRoot "c:/my_directory_tree/depot" 

    <Directory "C:/my_directory_tree/depot">
        Require all granted
        Options -MultiViews
    </Directory>

    ProxyPass /depot balancer://depot_cluster/
    ProxyPassReverse /depot balancer://depot_cluster/
    ProxyPreserveHost On

    <Proxy balancer://depot_cluster>
        BalancerMember http://127.0.0.1:3001/depot
    </Proxy>

    #ErrorLog  "|C:/Webserver/Apache/bin/rotatelogs.exe logs/example.com/%Y.%m.%d.example.com.error.log 86400" 
    #CustomLog "|C:/Webserver/Apache/bin/rotatelogs.exe logs/example.com/%Y.%m.%d.example.com.access.log 86400" 

combined

</VirtualHost>

然后运行我的应用程序:

thin -p 3000 -e production --prefix /depot start -p 3001

我已经预编译了我的资产,但也没有工作。

rake assets:precompile

为什么我在生产模式下运行我的应用程序?嗯...在真正的生产服务器中实现之前,我需要知道如何在 Windows 服务器中实现这个应用程序...

【问题讨论】:

    标签: ruby-on-rails ruby apache thin


    【解决方案1】:

    要为生产模式预编译资产,您需要运行

    RAILS_ENV=production rake assets:precompile
    

    问题的答案是将 apache 指向公共目录

    <Directory "C:/my_directory_tree/depot/public">
        Require all granted
        Options -MultiViews
    </Directory>
    

    【讨论】:

    • 是的,我已经从一开始就设置了RAILS_ENV=production,然后rake assets:precompile...。
    • 请看我的更新,我之前使用url('some-image.png')时遇到过这个错误。是否有任何 CSS 加载?
    • 我不明白。我必须更改所有样式表吗? ://
    • 如果损坏的只是图片,那么是的,您需要在所有样式表中将 url() 更改为 image-url()
    • 有意思,部署应用时通常需要给public文件夹。你会尝试使用&lt;Directory "C:/my_directory_tree/depot/public"&gt;
    猜你喜欢
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-20
    • 2017-09-25
    相关资源
    最近更新 更多