LOG IN SIGN UP
Documentation

Setting up redundant origin servers

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 user interface or using custom VCL.

Using the user interface

Set up redundant origins via the UI using these steps.

  1. In the Fastly application, define a health check and assign it to the primary origin server.

  2. Add a condition to the secondary origin server, with the following settings:

    Unhealthy primary condition

  3. Click the VCL button at the top to view the generated VCL, and confirm the following snippets appear in vcl_recv:

    # default conditions
    set req.backend = F_primary;
    
    # 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 application, 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:

    sub vcl_recv {
    #FASTLY recv
      set req.backend = F_<primary_origin>;
      if (!req.backend.healthy) {
        set req.backend = F_<secondary_origin>;
      }
      if (req.request != "HEAD" && req.request != "GET" && req.request != "FASTLYPURGE") {
        return(pass);
      }
      return(lookup);
    }
    

    To find the exact backend names, view the generated VCL using the VCL button at the top of the configuration control panel.

  4. Upload your VCL file.