> For the complete documentation index, see [llms.txt](/llms.txt).

# Use Infura as a backup for your node

In this tutorial, you'll use [Caddy](https://caddyserver.com/) to set up a reverse proxy with two upstreams, one from your own node, and one from Infura as a backup.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

- An [Ethereum project](/services/get-started/infura/) on Infura
- [Node.js installed](https://nodejs.org/en/download/)
- [Homebrew](https://brew.sh/) installed

## Steps[​](#steps "Direct link to Steps")

### 1\. Create a project directory[​](#1-create-a-project-directory "Direct link to 1. Create a project directory")

Create a new directory for your project. You can do this from the command line:

```
mkdir reverseProxy

```

Change into the new directory:

```
cd reverseProxy

```

### 2\. Install Caddy[​](#2-install-caddy "Direct link to 2. Install Caddy")

Install Caddy in the project directory using Homebrew:

```
brew install caddy

```

### 3\. Create a Node.js stub[​](#3-create-a-nodejs-stub "Direct link to 3. Create a Node.js stub")

You may be running your own Ethereum node, but for the sake of this tutorial, you can substitute a node with a Node.js stub. Create a file named `main.js` in the project directory with the following content:

```
const https = require('https')
const fs = require('fs')
const options = {
  key: fs.readFileSync('<PATH_TO_CERTIFICATE_KEY_FILE>.pem'),
  cert: fs.readFileSync('<PATH_TO_CERTIFICATE_FILE>.pem'),
}

const hostname = '127.0.0.1'
const port = 9000

const server = https.createServer(options, function (req, res) {
  res.statusCode = 200
  res.setHeader('Content-Type', 'text/plain')
  setTimeout(() => {
    res.end('Reverse proxy success!\n')
  }, 1000)
})

server.listen(port, hostname, () => {
  console.log(`Server running at https://${hostname}:${port}/`)
})

```

This sets up a backend HTTPS service running on `127.0.0.1:9000` (`localhost:9000`) and displays a success message if the proxy works.

warning

When creating a reverse proxy with multiple upstreams, Caddy requires _all_ upstream endpoints to be HTTP or HTTPS. In this tutorial, because the backup Infura endpoint is HTTPS, you must create a TLS certificate for your localhost (if you're not already using your own private HTTPS node).

You can [install and use mkcert](https://web.dev/how-to-use-local-https/#setup) to generate a certificate key file and certificate file for your stub:

```
brew install mkcert
mkcert -install
mkcert localhost

```

Replace `<PATH_TO_CERTIFICATE_KEY_FILE>` and `<PATH_TO_CERTIFICATE_FILE>` in `main.js` with the generated files.

### 4\. Run the Node.js stub[​](#4-run-the-nodejs-stub "Direct link to 4. Run the Node.js stub")

In a new terminal window, from your project directory, start the Node.js stub and leave that connection open:

```
node main.js

```

### 5\. Create the reverse proxy[​](#5-create-the-reverse-proxy "Direct link to 5. Create the reverse proxy")

To create the reverse proxy, create a text file named `Caddyfile` with the following content:

```
localhost:3000

reverse_proxy https://localhost:9000 https://sepolia.infura.io {
  header_up Host {/v3/<YOUR-API-KEY>}
}

```

Ensure you replace `<YOUR-API-KEY>` with the API key for your Ethereum project.

In this example, the reverse proxy retrieves information from `localhost:9000`, and redirects it to `localhost:3000`. If `localhost:9000` stops responding, Caddy will move on to retrieve information from the Sepolia endpoint. Using `header_up Host` allows you to include your API key to both the Sepolia and localhost endpoints.

### 6\. Run the reverse proxy[​](#6-run-the-reverse-proxy "Direct link to 6. Run the reverse proxy")

In a new terminal window, from your project directory, run the reverse proxy using Caddy:

```
caddy run

```

### 7\. Make a request[​](#7-make-a-request "Direct link to 7. Make a request")

In a new terminal window, make a curl request to `localhost`. The following example executes a `web3_clientVersion` request:

- Example CURL request
- Example result

```
curl http://localhost:3000/v3/<YOUR-API-KEY> \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "web3_clientVersion", "params": [], "id": 1}'

```

```
Reverse proxy success!

```

The success message from `main.js` should display, because you've asked the reverse proxy to go to `localhost:9000` first.

If you close the Node.js server and send the request again, you should get the result from the Sepolia node:

- Example CURL request
- Example result

```
curl http://localhost:3000/v3/<YOUR-API-KEY> \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "web3_clientVersion", "params": [], "id": 1}'

```

```
{"jsonrpc": "2.0", "id":1, "result": "Geth/v1.10.8-omnibus-aef5bfb3/linux-amd64/go1.16.7"}

```

The reverse proxy ignores the localhost node, since it's not functioning, and falls back to the Sepolia node.
