Generate sitemap is not working

I have a ruby on rails app deployed on with postgres using the free tier.

Using the sitemap_generator gem I am trying to ssh into my rails app on and generate the sitemap for my app.

The command from the gem is rake sitemap:refresh which creates a sitemap.xml.gz file in the public folder.

I face two errors, most of the times the above command fails and the log states that it cannot connect to my postgres db to generate the sitemap urls from my models.

The 2 times it managed to run it showed that the sitemap was successfully created with 8 links created but it seams like the file (public/sitemap.xml.gz) is either not persisting in my app or is not created at all.

Anyone has faced this issue? I guess my question is if it is possible to create a file with ssh connection to my app.


I’m not familiar with that gem, but the following from the readme looks like it would be helpful:

  • Supports read-only filesystems like Heroku via uploading to a remote host like Amazon S3

With our build flow, the ideal time to build a sitemap would be as a part of the deploy release flow. You likely have the following in your fly.toml:

  release_command = "./bin/rails db:prepare"

The way to proceed would be to create a file named (for example) bin/release, which contains the following lines:

./bin/rails db:prepare
rake sitemap:refresh

And then change your fly.toml to read:

  release_command = "./bin/release"

But this is predicated on you being able to upload the output to a remote host.

Thanks for the reply, based on your insights I managed to upload my sitemap on S3!

For anyone who might have the same issue, my working sitemap.rb

SitemapGenerator::Sitemap.default_host = ""

SitemapGenerator::Sitemap.public_path = 'tmp/'

SitemapGenerator::Sitemap.adapter ='bucket-name',
  acl: 'public-read', # Optional. This is the default.
  cache_control: 'private, max-age=0, no-cache', # Optional. This is the default.
  access_key_id: Rails.application.credentials.dig(:aws, :access_key_id),
  secret_access_key: Rails.application.credentials.dig(:aws, :secret_access_key),
  region: 'your-aws-region'

SitemapGenerator::Sitemap.create do

  add '/'
  add '/about'
  add '/contact'


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.