User

Nginx Reverse Proxy

How Opterius configures Nginx to proxy your domain to a Node.js app.

Last updated 1775606400

When you deploy a Node.js app through the panel, Opterius automatically rewrites the domain's Nginx vhost to forward all requests to your app's port.

What Gets Configured

server {
    listen 443 ssl http2;
    server_name yourdomain.com www.yourdomain.com;

    # SSL certificate (from Let's Encrypt)
    ssl_certificate     /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;

    location / {
        proxy_pass         http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection 'upgrade';
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}

The Upgrade and Connection headers enable WebSocket support — if your app uses socket.io or any WebSocket library, it will work without additional configuration.

SSL Certificate

For the proxy to work on HTTPS, the domain must have a valid SSL certificate. Issue one before deploying if you haven't already.

If no certificate exists at deployment time, Nginx will be configured for HTTP only (port 80). Re-deploy after issuing the certificate to get HTTPS.

Getting the Real Client IP

Your app receives the original client IP in the X-Forwarded-For header. In Express:

// Trust the proxy (put this before your routes)
app.set('trust proxy', 1);

app.get('/', (req, res) => {
    console.log(req.ip); // real client IP
});

In other frameworks, read X-Real-IP or X-Forwarded-For from the request headers.

Serving Static Files via Nginx

If you want Nginx to serve static files directly (bypassing Node.js) for better performance, you can add a custom Nginx directive on the domain settings page:

location /static/ {
    alias /home/myuser/mydomain.com/public/;
    expires 30d;
    add_header Cache-Control "public, immutable";
}

Go to Domains → your domain → Nginx Directives and add the block there.

Multiple Apps on Subdomains

Each subdomain can have its own Node.js app on a different port:

Subdomain App Port
api.yourdomain.com REST API 3001
ws.yourdomain.com WebSocket server 3002
admin.yourdomain.com Admin panel 3003

Deploy each app separately, selecting the corresponding subdomain.

Next Steps