【问题标题】:How to setup static page with css in subdirectory in rails public directory如何在rails公共目录的子目录中使用css设置静态页面
【发布时间】:2019-12-14 21:35:26
【问题描述】:

我正在尝试在我的 public/blog 目录中设置 jekyll 博客。

对于这个问题,假设我只想让public/blog 目录与index.htmlcss/site.css 与此页面的css。

我正在使用 capistrano 部署它,所以我将 public/blog 添加到 linked_dirs

index.html:

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="css/site.css">
  </head>
  <body>
    <h1>Hello World</h1>
  </body>
</html>

css/site.css:

h1 {
  color: red;
}

现在cap production deploy 之后我可以访问domain.com/blog 并看到Hello World 标头,但它不会加载css 文件。

我收到Failed to load resource: the server responded with a status of 404 (Not Found) 错误。

你知道我怎样才能让它工作吗?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-5 capistrano


    【解决方案1】:

    这更像是一个 nginx 问题。

    我将此添加到我的站点 nginx 文件中:

      location ^~ /blog/css/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 2018-11-09
      • 2014-05-05
      • 2012-02-08
      • 2016-05-29
      相关资源
      最近更新 更多