在生产中找不到站点地图文件

Sitemap file not found on production

我正在使用 sitemap_generator gem 并且在 config/sitemap.rb 有以下配置:

require 'rubygems'
require 'sitemap_generator'

SitemapGenerator::Sitemap.default_host = 'http://www.localhost.com'

SitemapGenerator::Sitemap.create do
  add '/', :changefreq => 'daily', :priority => 0.9
  add '/contact', :changefreq => 'weekly'

  User.find_each do |user|
    add users_path(user), lastmod: user.updated_at
  end
end

SitemapGenerator::Sitemap.ping_search_engines

该应用托管在 heroku 上。当我执行 heroku run rake sitemap:refresh 时,我得到以下结果

In '/app/public/':
+ sitemap.xml.gz                                          76 links /    1.53 KB
Sitemap stats: 76 links / 1 sitemaps / 0m00s

Pinging with URL 'http://www.localhost.com/sitemap.xml.gz':
  Successful ping of Google
  Successful ping of Bing

Pinging with URL 'http://www.localhost.com/sitemap.xml.gz':
  Successful ping of Google
  Successful ping of Bing

现在我试图找到 sitemap.xml.gz 文件,但它在 heroku 上找不到。我做了 heroku run rake lsheroku run rake ls tmpheroku run rake ls public,但找不到。

过去我在 sitemap.rb 上也有这两行:

SitemapGenerator::Sitemap.public_path = 'tmp/'
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'

但仍未在此文件夹上生成站点地图。有什么线索是我做错了并且没有生成吗?

Heroku 没有永久文件系统。因此,在 heroku 上的任何上传都不是 permanent.Check 此文档以获取更多信息 https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem

我找到了解决方案 here

我必须使用 fog-aws gem 并配置 sitemap.rb 文件:

# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "http://example.com"
# pick a place safe to write the files
SitemapGenerator::Sitemap.public_path = 'tmp/'
# store on S3 using Fog (pass in configuration values as shown above if needed)
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new
# inform the map cross-linking where to find the other maps
SitemapGenerator::Sitemap.sitemaps_host = "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com/"
# pick a namespace within your bucket to organize your maps
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'

不要忘记设置适配器环境变量:

SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(fog_provider: 'AWS',
                                     aws_access_key_id: <your-access-key-id>,
                                     aws_secret_access_key: <your-access-key>,
                                     fog_directory: <your-bucket>,
                                     fog_region: <your-aws-region e.g. us-west-2>)