2016-07-07 12 views
1

https://anthony-galli.s3.amazonaws.com/sitemaps/sitemap.xml.gzに行ったときに私のサイトマップがどのように見えるのでしょうか?私の代わりに直面しています:「このXMLファイルは表示されません...」サイトマップの表示方法

それは私が実行したときに、正しく構築されたサイトマップのように見える
This XML file does not appear to have any style information associated with it. The document tree is shown below. 
<Error> 
<Code>AccessDenied</Code> 
<Message>Access Denied</Message> 
<RequestId>25B779FB11146233</RequestId> 
<HostId> 
94TdmdgzvdGCMVfKFZYL7Z3JASDFSa18N1YdUoMCtNa3qx6UHajPfMQSeFqfDmgYFHf 
</HostId> 
</Error> 

Anthony-Gallis-MacBook-Pro:blog galli01anthony$ heroku run rake sitemap:refresh --trace 
WARNING: Toolbelt is currently updating 
Running rake sitemap:refresh --trace on ⬢ anthony-galli... up, run.5920 
** Invoke sitemap:refresh (first_time) 
** Invoke sitemap:create (first_time) 
** Invoke sitemap:require_environment (first_time) 
** Execute sitemap:require_environment 
** Invoke environment (first_time) 
** Execute environment 
** Execute sitemap:create 
In '/app/public/sitemaps/': 
+ sitemap.xml.gz           24 links/982 Bytes 
Sitemap stats: 24 links/1 sitemaps/0m00s 

Pinging with URL 'http://www.anthonygalli.com/sitemap.xml.gz': 
    Successful ping of Google 
    Successful ping of Bing 
** Execute sitemap:refresh 

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

routes.rbを

get '/sitemap.xml.gz', to: redirect("https://#{ENV['AWS_BUCKET']}.s3.amazonaws.com/sitemaps/sitemap.xml.gz"), as: :sitemap 

production.rb

config.paperclip_defaults = { 
    :storage => :s3, 
    :s3_credentials => { 
     :region => ENV['AWS_REGION'], 
     :bucket => ENV['AWS_BUCKET'], 
     :access_key_id => ENV['AWS_ACCESS_KEY_ID'], 
     :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] 
    } 
    } 

のconfig/sitemap.rb

SitemapGenerator::Sitemap.default_host = 'http://www.anthonygalli.com/' 
SitemapGenerator::Sitemap.public_path = 'public/sitemaps/' 

SitemapGenerator::Sitemap.create do 
    add posts_path, changefreq: 'daily' 
    Post.find_each do |post| 
    add post_path(post.slug), lastmod: post.updated_at 
    end 
end 

SitemapGenerator::Sitemap.ping_search_engines 

のlib /タスク/ sitemap.rake

require 'aws' 

desc 'Upload the sitemap files to S3' 
task upload_to_s3: :environment do 
    puts 'Starting sitemap upload to S3...' 
    s3 = Aws::S3::Resource.new 
    bucket = s3.bucket(ENV['S3_BUCKET']) 
    Dir.entries(File.join(Rails.root, 'tmp', 'sitemaps')).each do |file_name| 
    next if %w(. .. .DS_Store).include? file_name 
    path = "sitemaps/#{file_name}" 
    file = File.join(Rails.root, 'tmp', 'sitemaps', file_name) 
    object = bucket.object(path) 
    object.upload_file(file) 
    puts "Saved #{file_name} to S3" 
    end 
end 

namespace :sitemap do 
    # ... 
    desc 'Create the sitemap, then upload it to S3 and ping the search engines' 
    task create_upload_and_ping: :environment do 
    Rake::Task["sitemap:create"].invoke 

    Rake::Task["sitemap:upload_to_s3"].invoke 

    SitemapGenerator::Sitemap.ping_search_engines('http://www.anthonygalli.com/sitemap.xml.gz') 
    end 
end 

enter image description here

私はこのチュートリアルに沿って続く:http://cookieshq.co.uk/posts/creating-a-sitemap-with-ruby-on-rails-and-upload-it-to-amazon-s3/

+0

おそらくs3バケット内で許可した権限に問題がありますか? – treiff

答えて

2

GetPolicy権限がない場合、Amazon S3は403 アクセス拒否エラーを返します。

{ 
    "Id": "Policy1467935016977", 
    "Version": "2012-10-17", 
    "Statement": [ 
    { 
     "Sid": "Stmt1467935004623", 
     "Action": [ 
     "s3:GetObject" 
     ], 
     "Effect": "Allow", 
     "Resource": "arn:aws:s3:::anthony-galli/sitemaps/*", 
     "Principal": "*" 
    } 
    ] 
} 

UPDATE

: - http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETpolicy.html

特定のフォルダ/sitemapsへのパブリックアクセスを許可するようにS3バケットに(https://awspolicygen.s3.amazonaws.com/policygen.htmlで作成した)このポリシーを追加します。問題を診断するために、嘆願書AWSがオブジェクトのURLを指定して質問を更新します。

Screenshot of AWS S3 Console

+1

ありがとうございました!私はあなたのコードをconsole.aws.amazon.comのBucket Policy Editorに追加しました。私はまだエラーが発生します。私はそれを正しい場所に置いたのでしょうか、あなたのコードは間違っていますか?私はあなたが私に与えたリンクで私自身のポリシーを生成しようとしましたが、ARNまたはプリンシパルが何であるかをidkに伝えました。再度、感謝します! –

+0

私は後で見て、私の答えを更新します。 – SoAwesomeMan

+0

ちょうどチェックしました。このコードは、バケツポリシーエディタ(https://s3-us-west-2.amazonaws.com/step1profit/sitemaps/sitemap.xml.txt)でコンソールに表示されます。コンソールの 'sitemap.xml.gz'ファイルに移動し、それを選択してください。プロパティ列は右側に表示されます。プロパティで、 "リンク:"値をコピーして、ここでそれを過ぎてください。 – SoAwesomeMan

関連する問題