Skip to content

Instantly share code, notes, and snippets.

@EdwardPrentice
Last active March 20, 2022 16:26
Show Gist options
  • Save EdwardPrentice/a5eb2d481a1dce43b354c43f4d3ce450 to your computer and use it in GitHub Desktop.
Save EdwardPrentice/a5eb2d481a1dce43b354c43f4d3ce450 to your computer and use it in GitHub Desktop.
Nginx config to route to multiple Eth1 providers
# turn off default logging
access_log off;
# Create our own format including $server_name
log_format main escape=none
#'$remote_addr - $remote_user '
'[$time_local] '
'$request $status '
#'"$http_user_agent" '
#'"$http_origin" '
'$server_name '
'\n $request_body' # this allows us to see the json payload in the POST requests to the API
;
# declare a collection of eth1 providers
upstream eth1-providers {
server 127.0.0.1:8443;
server 127.0.0.1:8444;
}
# define an eth1 provider
server {
server_name 'mainnet.infura.io';
listen 127.0.0.1:8443;
location / { proxy_pass https://mainnet.infura.io/v3/0b0b00329ed940a3a550a975941d1b86; }
access_log /var/log/nginx/access.log main;
}
# define an eth1 provider
server {
server_name 'mainnet.alchemyapi.io';
listen 127.0.0.1:8444;
location / { proxy_pass https://eth-mainnet.alchemyapi.io/v2/rNimfONsJagljpBDABGySslN0YeorXtU; }
access_log /var/log/nginx/access.log main;
}
# define the external interface to talk to the collection of eth1 providers
server {
listen 127.0.0.1:6666;
location / { proxy_pass http://eth1-providers; }
# proxy_set_header origin https://<your-ip-here>; Optional, can be used to secure Infura to a single origin
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment