【问题标题】:Enable serving of images, stylesheets, and JavaScripts from an asset server of Rails Application允许从 Rails 应用程序的资产服务器提供图像、样式表和 JavaScript
【发布时间】:2018-10-16 08:56:45
【问题描述】:

我通过从 production.rb 转换此配置,启用了从资产服务中提供图像、样式表和 JavaScript 的服务

config.action_controller.asset_host = 'https://assets.example.com'

当我单击资产链接时,所有资产都从该 URL 的 https://assets.example.com 开始提供服务,呈现 404 错误页面。我也为此子域添加了 DNS A 记录。

我正在使用 Apache2 和 Mod Passenger。

我很困惑。请建议我正确的解决方案。

【问题讨论】:

    标签: ruby-on-rails ruby apache2


    【解决方案1】:

    我解决了。

    我删除了 assets 子域的 A 记录,并创建了一个指向根域的 assets 的 cname 记录。

    CNAME assets is an alias of www.example.com 
    

    然后我将 assets.example.com 作为 ServerAlias 添加到 example.com.conf 文件中

    ServerAlias assets.example.com
    

    为了防止 assets.example.com 浏览自身,我添加了一个 mod 重写规则来将 assets.example.com 重定向到 www.example.com。

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule ^/(.*)$ https://www.example.com/$1 [L,R=301]
    RewriteCond %{HTTP_HOST} ^assets\.(.*)$ [NC]
    RewriteRule ^/(.*)$ https://www.example.com/$1 [L,R=301]
    </IfModule>
    

    它现在可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      • 2015-06-12
      • 2017-08-14
      • 2011-12-04
      • 2015-09-14
      • 2012-01-01
      相关资源
      最近更新 更多