Nginx - Basics
π§ NGINX β Basic Setup + Usage
NGINX is a web server thatβs also commonly used as a reverse proxy β a tool to forward requests to services running on your server, like blockchain RPCs, APIs, dashboards, etc.
π οΈ Step 1: Install NGINX on Ubuntu
sudo apt update
sudo apt install nginx -y
Check if itβs running:
sudo systemctl status nginx
Start or enable if needed:
sudo systemctl start nginx
sudo systemctl enable nginx
π Step 2: Allow HTTP/HTTPS Ports in Firewall
If you're using ufw
, allow necessary ports:
sudo ufw allow 'Nginx Full'
π Step 3: Basic Web Server Test
Open your serverβs public IP in a browser, you should see the NGINX welcome page:
http://<your-server-ip>
π Step 4: Using NGINX as Reverse Proxy (for RPC / API)
Letβs say your nodeβs RPC is running on:
http://localhost:26657
And you want to expose it via:
https://rpc.yourdomain.com
π Create Config File for Subdomain
sudo nano /etc/nginx/sites-available/rpc.yourdomain.com
Paste this:
server {
listen 80;
server_name rpc.yourdomain.com;
location / {
proxy_pass http://localhost:26657;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
π Enable the Site
sudo ln -s /etc/nginx/sites-available/rpc.yourdomain.com /etc/nginx/sites-enabled/
Then test and reload:
sudo nginx -t
sudo systemctl reload nginx
Now open: http://rpc.yourdomain.com
π Step 5: Add Free SSL (HTTPS) with Certbot
Install Certbot and plugin for NGINX:
sudo apt install certbot python3-certbot-nginx -y
Run Certbot:
sudo certbot --nginx
Follow the instructions. Certbot will:
Automatically get an SSL cert from Let's Encrypt
Reload NGINX with secure HTTPS
To auto-renew:
sudo systemctl list-timers | grep certbot
π§ͺ Other Use Cases for NGINX
Purpose
Example
Expose RPC
rpc.yourdomain.com -> localhost:26657
Expose Explorer
explorer.yourdomain.com -> localhost:3000
Protect with auth
Use auth_basic
in config
Rate limit RPC
Use limit_req
module
Proxy with HTTPS
Add Certbot SSL on any service/subdomain
π§ Tips
Use separate files in
sites-available/
for each service.Always test config with:
sudo nginx -t
Reload NGINX after changes:
sudo systemctl reload nginx
Protect sensitive endpoints using IP allowlist or auth
π‘ NGINX makes it easy to manage many services on one VPS. Itβs lightweight, powerful, and essential in modern DevOps.
Next β Learn to:
Set up Basic Authentication
Add rate limiting to RPC endpoints
Run multiple subdomains on a single VPS
Last updated