Getting started
Basics
Domains & Origins
Performance

Configuration
Basics
Conditions
Dictionaries
Domains & Origins
Request settings
Cache settings
Headers
Responses
Performance
Purging
Custom VCL
Image optimization
Video

Security
Access Control Lists
Monitoring and testing
Securing communications
Security measures
TLS
Web Application Firewall

Integrations
Logging endpoints
Non-Fastly services

Diagnostics
Streaming logs
Debugging techniques
Common errors

Account info
Account management
Billing
User access and control

Reference

    Setting up redundant origin servers

      Last updated October 02, 2018

    Sometimes you want to set up two different origin servers, one as a primary and one as a backup in case the primary becomes unavailable. You can do this via the web interface or using custom VCL.

    Using the user interface

    Set up redundant origins via the user interface using these steps.

    1. Log in to the Fastly web interface and click the Configure link.
    2. From the service menu, select the appropriate service.
    3. Click the Edit configuration button and then select Clone active. The Domains page appears.
    4. Click the Origins link. The Origins page appears.
    5. In the Health Checks area, define a health check and assign it to the primary origin server.
    6. In the Hosts area, find your secondary origin server and click the Attach a condition link.

      an example secondary origin server

      The Add a condition window appears.

      an example add a condition window

    7. Click Create a new request condition. The Create a new request condition window appears.

      an example create a new condition window

    8. Fill out the Create a new request condition fields as follows:
      • In the Name field, type the name of your request condition (for example, Primary Unhealthy).
      • In the Apply if field, type !req.backend.healthy.
    9. Click the Save and apply to button. The Hosts area now displays the condition that must be met (Primary Unhealthy) in order for your secondary origin server to begin being used.

      hosts condition primary unhealthy that will trigger use of the secondary origin server

      Once you've added the condition to your secondary origin server, the VCL generated by Fastly will reflect the new condition.

    10. Preview the VCL, and confirm the following snippets appear in vcl_recv:

      1
      2
      
      # default conditions
      set req.backend = F_primary;
      
      1
      2
      3
      4
      5
      
      # Request Condition: primary unhealthy Prio: 10
      if (!req.backend.healthy) {
        set req.backend = F_secondary;
      }
      #end condition
      

    Using custom VCL

    Set up redundant origins with custom VCL using these steps.

    1. In the Fastly web interface, define a health check and assign it to the primary origin server.
    2. Copy the boilerplate VCL from our guide on mixing Fastly VCL with custom VCL, and paste it into a new file.
    3. Replace the vcl_recv sub with:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      
       sub vcl_recv {
       #FASTLY recv
         set req.backend = F_<primary_origin>;
         if (!req.backend.healthy) {
           set req.backend = F_<secondary_origin>;
         }
         if (req.method != "HEAD" && req.method != "GET" && req.method != "FASTLYPURGE") {
           return(pass);
         }
         return(lookup);
       }
      

      To find the exact backend names, view the generated VCL.

    4. Upload your VCL file.
    Back to Top