【nginx】sitemapをpublic/sitemaps/下に作成して、google先生にクローリングしてもらう
諸々の事情で、sitemapをs3にあげていたんだけど ふと思うことがあって、public下に移した
config/sitemap.rb
SitemapGenerator::Sitemap.default_host = "https://hogehoge.jp" SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/' SitemapGenerator::Sitemap.create do Song.all.find_each do |song| add song_path(song), lastmod: song.updated_at end end
nginx側のroute設定
/etc/nginx/nginx.conf 等に
# google search console上で、/sitemap.xmlで登録したかったら location /sitemap.xml { root /var/www/wayak/current/public/sitemaps; } # google search console上で、/sitemaps/sitemap.xml.gzで登録したかったら location ~ ^/sitemaps/(robots.txt|sitemap(.*).xml.gz) { root /var/www/wayak/current/public; }
2つ目は、sitemap2.xml.gzのように sitemapが複数ファイルに分かれてもいいようにしてある。