【问题标题】:"This XML file does not appear..." How to see sitemap?“此 XML 文件未出现...” 如何查看站点地图?
【发布时间】:2016-07-07 23:28:55
【问题描述】:

当我转到https://anthony-galli.s3.amazonaws.com/sitemaps/sitemap.xml.gz 时,如何查看我的站点地图的外观?相反,我遇到了:

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/tasks/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

我按照本教程进行操作:http://cookieshq.co.uk/posts/creating-a-sitemap-with-ruby-on-rails-and-upload-it-to-amazon-s3/

【问题讨论】:

  • 您在 s3 存储桶中授予的权限可能有问题?

标签: ruby-on-rails ruby amazon-web-services amazon-s3 sitemap


【解决方案1】:

如果您没有 GetPolicy 权限,Amazon S3 会返回 403 访问被拒绝错误。 http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETpolicy.html

将此策略(使用 https://awspolicygen.s3.amazonaws.com/policygen.html 创建)添加到您的 s3 存储桶,以允许公共访问特定文件夹 /sitemaps

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

更新

为了诊断问题,请使用 AWS 提供的对象 URL 更新问题。

【讨论】:

  • 谢谢伙计!我将您的代码添加到 console.aws.amazon.com 上的存储桶策略编辑器。我仍然得到错误。我把它放在正确的位置还是你的代码不正确?我尝试使用您给我的链接自行生成策略,但我不知道 ARN 或 Principal 是什么。再次感谢!
  • 刚刚检查过。该代码通过控制台上的存储桶策略编辑器为我工作:s3-us-west-2.amazonaws.com/step1profit/sitemaps/sitemap.xml.txt。请在控制台中导航到您的sitemap.xml.gz 文件并选择它。属性列应出现在右侧。在属性中,复制“链接:”值并将其粘贴到此处。
  • 再次感谢您的帮助 :) 好的,所以我截取了页面的屏幕截图 [添加到问题中] 我认为您在谈论确保我们在同一页面上 console.aws.amazon.com/s3/home?region=us-east-1# ; )
  • 好的开始,差不多了。从屏幕截图中的页面: 1)单击存储桶名称anthony-galli,应该会出现存储桶视图; 2) 点击文件夹“站点地图”,您应该会看到文件sitemap.xml.gz; 3)点击sitemap.xml.gz,蓝色复选框应该被选中; 4)点击右上角导航栏上的Properties,应该会出现一个右栏; 5)找到Link,复制它并用它更新你的问题。我会用截图更新我的答案。
  • 嗨,哥们,抱歉耽搁了。我终于想出了如何获取sitemap.xml.txt 链接。你说把它贴在这里:s3.amazonaws.com/anthony-galli/sitemaps/sitemap.xml.gz。不知道把它放在哪里来消除有问题的错误。感谢您的耐心等待!
猜你喜欢
  • 2015-01-10
  • 2013-12-18
  • 1970-01-01
  • 2012-08-16
  • 2019-01-18
  • 2013-10-12
  • 2011-01-15
  • 2017-04-01
  • 1970-01-01
相关资源
最近更新 更多