Skip to content

Instantly share code, notes, and snippets.

@Bambarello
Forked from Gribnik2K/EthNODE+nginx
Last active January 18, 2024 10:21
Show Gist options
  • Save Bambarello/57ffde62fdc49fb602452df7a41eea0e to your computer and use it in GitHub Desktop.
Save Bambarello/57ffde62fdc49fb602452df7a41eea0e to your computer and use it in GitHub Desktop.
client_max_body_size 1280M;
upstream mainnet_rpc {
least_conn;
server rpc-eth2.node.com:7999 max_fails=3 fail_timeout=2s weight=1;
server rpc-eth1.node.com:7999 max_fails=3 fail_timeout=2s weight=1;
}
server {
listen 127.0.0.1:7999;
server_name localhost;
access_log /var/log/nginx/loadbalancer.log;
client_max_body_size 1280M;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://mainnet_rpc/;
}
}
########ETH-NODE########
apt-get update; \
apt-get upgrade -y; \
apt-get install nginx -y; \
rm /etc/nginx/sites-enabled/*; \
nano /etc/nginx/sites-enabled/ether.conf
#Туда вот это ничего не меняя.
/начало файла
client_max_body_size 1280M;
upstream eth_rpc {
server 127.0.0.1:8545;
}
upstream eth_ws {
server 127.0.0.1:8546;
}
server {
listen 7999;
listen [::]:7999;
server_name localhost;
access_log off;
client_max_body_size 1280M;
location ^~ /secrettokenrpc {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://eth_ws;
}
location ^~ /secrettokenrpc {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://eth_rpc/;
}
}
/конец файла
# change the worker connections
nano /etc/nginx/nginx.conf
events {
worker_connections 4096;
multi_accept on;
}
systemctl daemon-reload; \
systemctl start nginx; \
systemctl enable nginx; \
systemctl restart nginx
Check
curl http://IP_ETH_SERVERA/rpc
Answer
Used HTTP Method is not allowed. POST or OPTIONS is required
Ok!
Firewall
iptables -A INPUT -s IP_GRAPH_SERVER -j RETURN
iptables -A INPUT -p tcp --dport 80 -j DROP
or
ufw allow from IP_GRAPH_SERVER to any port 80
##############################################################################################################
# Optional Тут нода эфира не лезет в локалку.
# ETH.SERVICE
nano /etc/systemd/system/openethereum.service
/начало файла
[Unit]
Description=OpenEthereum
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/bin/openethereum \
--no-periodic-snapshot \
--pruning=archive \
--tracing=on \
--no-warp \
--db-compaction=ssd \
--cache-size=100000 \
--max-peers=64 \
--jsonrpc-threads=8 \
--jsonrpc-server-threads=100 \
--jsonrpc-hosts=all \
--jsonrpc-cors=all \
--allow-ips=public \
--ws-origins=all \
--ws-hosts=all
User=root
Group=root
Restart=on-failure
# Specifies which signal to use when killing a service. Defaults to SIGTERM.
# SIGHUP gives openethereum time to exit cleanly before SIGKILL (default 90s)
KillSignal=SIGHUP
[Install]
WantedBy=default.target
/конец файла
##############################################################################################################
### далее на ноду с графом###
И тут вот наша стартовая строка... Доступ вида http://IP_NODE_ETH/rpc
cargo run -p graph-node --release -- \
--postgres-url postgresql://postgres:xxx@localhost:5432/graph-node \
--ethereum-rpc mainnet:http://IP_NODE_ETH/rpc \
--ipfs https://testnet.thegraph.com/ipfs/
##############################################################################################################
# balancer
# 1) install nginx (instructions above)
nano /etc/nginx/sites-enabled/ether.conf
# file begin
upstream eth {
server 1.1.1.1:8080;
server 2.2.2.2:8080;
}
server {
listen 127.0.0.1:7999;
server_name localhost;
access_log /var/log/nginx/loadbalancer.log;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://eth;
}
}
#file end
#test config
nginx -t
sudo systemctl daemon-reload; \
sudo systemctl start nginx; \
sudo systemctl status nginx; \
sudo systemctl enable nginx; \
sudo systemctl restart nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment