LoginSignup
2
1

More than 5 years have passed since last update.

ecs & rails & nginx環境 で sitemapを作り、s3にアップし利用する

Posted at

やったこと

  • sitemapをsitemap_generatorのgemを使って作っていたのだけれども、複数台環境 & ecs導入に伴ってs3上に置き場を変えた

sitemapの作成

gem sitemap_generatorを利用
https://github.com/kjvarga/sitemap_generator
詳しい記事がqiita上にたくさんあるので割愛

ECS利用にともない、rake sitemap:refreshを実行するタスクを新規作成

sitemapのs3へのアップロード

SitemapGenerator::Sitemap.default_host = "https://yourhost.com"
SitemapGenerator::Sitemap.sitemaps_host = "https://your-s3-bucket.s3.amazonaws.com/"
SitemapGenerator::Sitemap.public_path = 'public/'
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'

SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new({
  fog_provider: 'AWS',
  fog_directory: 'your-bucket-name',
  fog_region: '*******',
  aws_access_key_id: '*******',
  aws_secret_access_key: '*******',
})

nginx confの編集

sitemapだけs3だったので、file指定で変更

  location ~* ^/sitemap.xml.gz {
       set $s3_bucket        'your-bucket-name.s3.amazonaws.com';
       set $url_full         "sitemaps/sitemap.xml.gz";

       proxy_http_version     1.1;
       proxy_set_header       Host $s3_bucket;
       proxy_set_header       Authorization '';
       proxy_hide_header      x-amz-id-2;
       proxy_hide_header      x-amz-request-id;
       proxy_hide_header      Set-Cookie;
       proxy_ignore_headers   "Set-Cookie";
       proxy_buffering        off;
       proxy_intercept_errors on;

      resolver               10.0.0.2 valid=5s;
      resolver_timeout       3s;

      proxy_pass             http://$s3_bucket/$url_full;
  }

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1