【问题标题】:Images are not loading on production图像未在生产中加载
【发布时间】:2015-06-05 13:41:55
【问题描述】:

我正在将 Rails 应用程序部署到 Digitalocean。我正在与 Apache 和Passenger 合作。我能够在生产中本地运行我的应用程序并且工作正常。我在 localhost 上遇到了同样的问题,但做了以下事情来使它工作。我在本地使用 Webrick 服务器,在 Ubuntu 中使用 Apache。

安装了这些 gem:

therubyracer
execjs

我将此添加到 production.rb

config.serve_static_files = true
config.assets.compile = true
config.assets.precompile =  ['*.js', '*.css']

然后我做了

RAILS_ENV=production bundle exec rake assets:precompile

我尝试在 Ubuntu 中进行相同的生产,但一切似乎都很好,但图像除外。

这就是我在 /etc/apache2/sites-available/metalmind.com.co.conf 中的内容

    <VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin something@hotmail.com
    ServerName metalmind.com.co
    ServerAlias www.metalmind.com.co
    DocumentRoot /home/luisjar/Metalmind_2/public
    <Directory "/home/luisjar/Metalmind_2/public">
    Options All
    AllowOverride All
    Require all granted
    </Directory>
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails ruby apache digital-ocean


    【解决方案1】:

    要在生产环境中加载图像,您需要检查某些事项 -

    1) 在没有加载图片的情况下生成的 url 是什么(使用 firebug 查看 url 路径)

    2) 你的图片存放在哪里,是在图片下还是在公共文件夹下。

    3) 您是否使用此命令 (rake assets:precompile RAILS_ENV=production) 为生产预编译了资产

    此外,在此类情况下,这些日志也很有帮助。

    【讨论】:

      猜你喜欢
      • 2019-06-26
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 2023-02-07
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多