Skip to content

Latest commit

 

History

History
159 lines (109 loc) · 4.47 KB

setup.md

File metadata and controls

159 lines (109 loc) · 4.47 KB

Variables

These variables are referenced in the setup instructions below to avoid hardcoding values unnecessarily.

REQUEST_LOGS_S3_REGION: AWS region hosting the request logs S3 bucket
REQUEST_LOGS_S3_BUCKET: Name of the S3 bucket that Fastly will send request logs to
REQUEST_LOGS_ROLE_ARN: The ARN of the policy that grants Fastly's AWS account permission to write into the S3 request logs bucket

1. Create AWS S3 bucket for storing logs

Create a new bucket using AWS web console.

  • Bucket name: ${REQUEST_LOGS_S3_BUCKET}
  • ACLs disabled
  • Block all public access
  • Bucket versioning: Disable

Leave all other settings with their default values.


2. Create AWS IAM Role and Policy

This is a simplified version of Fastly's instructions.

Policy

  • Create a new policy using the JSON editor:
{
    "Version": "2012-10-17",
    "Statement": {
        "Effect": "Allow",
        "Action": "s3:PutObject",
        "Resource": "arn:aws:s3:::${REQUEST_LOGS_S3_BUCKET}/*"
    }
}
  • Name: WriteAccessToRubyforgeOrgFastlyLogsS3Bucket
  • Description: Grants write access to the ${REQUEST_LOGS_S3_BUCKET} S3 bucket. Intended to be used by an IAM Role that grants the Fastly AWS account access to our account.

Role

  • Click "Create role"
  • Choose "AWS account"
  • Choose "Another AWS account"
  • Enter "717331877981" as the Account ID (This is Fastly's AWS ID)
  • Check "Require external ID"
  • Enter Ruby Central's Fastly Customer ID (available at https://manage.fastly.com/account/company) as the "External ID"
  • Click "Next"
  • Check the "WriteAccessToRubyforgeRedirectLogsS3Bucket" Policy created in the previous step
  • Click "Next"
  • Role name: "RubyCentralFastlyLogStreaming"
  • Role description: Allows Fastly AWS account to stream logs from Ruby Central's Fastly account.
  • Click "Create role"
  • Find and click on the new role in the list
  • Make a note of the ARN (${REQUEST_LOGS_ROLE_ARN}) as we need this when setting up Log Streaming in Fastly

3. Setup GitHub Pages

  • Configure GitHub Pages to publish from the gh-pages branch in this repository
  • Set the custom domain of the GitHub Pages site to redirects-origin.rubyforge.org so that it can be used as the origin in Fastly
  • Configure redirects-origin.rubyforge.org as a CNAME pointing to rubycentral.github.io (this assumes that the GitHub Pages site is in the Ruby Central account)

4. Setup CDN in Fastly

Domains

  • *.rubyforge.org
  • rubyforge.org

Origins

  • Name: github-pages
  • Address: redirects-origin.rubyforge.org
  • Enable TLS: Yes
  • Verify certificate?: Yes
  • Certificate hostname: redirects-origin.rubyforge.org
  • SNI hostname: redirects-origin.rubyforge.org
  • Override host: redirects-origin.rubyforge.org

Leave all other settings with their default values.

Settings

Redirect traffic to www subdomains

  • Domain: rubyforge.org
  • Status: 301

Leave all other settings with their default values.

Logging

Click "Create endpoint" and then "Create endpoint" next to "Amazon S3".

  • Name: S3
  • Bucket name: ${REQUEST_LOGS_S3_BUCKET}
  • Domain: s3.${REQUEST_LOGS_S3_REGION}.amazonaws.com
  • Access method: IAM role
  • IAM role: ${REQUEST_LOGS_ROLE_ARN}

VCL snippets

Match redirect

Click "+Create snippet".

  • Name: Match redirect
  • Type (placement of snippet): within subroutine - recv (vcl_recv)
  • VCL: content of config/match-redirects.vcl

Handle redirect

Click "+Create snippet".

  • Name: Match redirect
  • Type (placement of snippet): within subroutine - error (vcl_error)
  • VCL: content of config/handle-redirects.vcl

5. Check that the Fastly config is working

curl -I http://151.101.0.204 -H"Host: gems.rubyforge.org"
# Should 301 redirect to https://rubygems.org

curl -I http://151.101.0.204 -H"Host: rubyforge.org"
# Should 301 redirect to http://www.rubyforge.org

curl -I http://151.101.0.204 -H"Host: mocha.rubyforge.org"
# Should 301 redirect to https://github.com/freerange/mocha

6. Configure DNS to point to Fastly

When rubyforge.org was active it was only available using http, and gems.rubyforge.org is still only available using http so we're configuring http-only DNS to point to Fastly:

rubyforge.org. A 151.101.0.204
rubyforge.org. A 151.101.64.204
rubyforge.org. A 151.101.128.204
rubyforge.org. A 151.101.192.204

*.rubyforge.org CNAME nonssl.global.fastly.net.