🌐

Nginx Configuration

Configure Nginx reverse proxy for V5 Exchange Provider

Need Help?

For additional support, visit our Support Center

📖 Overview

After completing the V5 Exchange Provider setup steps above, you'll need to configure Nginx if your server uses it instead of Apache. This configuration provides reverse proxying, WebSocket support, compression, and various connection optimizations.

When to Use This Guide

Use this configuration if you're running Nginx instead of Apache. This guide assumes you've completed the basic V5 setup process.

🔧 Method 1: Virtualmin Configuration

1

Access Virtualmin Nginx Settings

Click the Virtualmin tab in your hosting control panel.

2

Select Virtual Server

Select the virtual server (domain) you want to configure.

3

Navigate to Nginx Configuration

Navigate to Services and then open Configure Nginx Website in a new tab.

4

Edit Nginx Directives

Click Edit Nginx Directives.

5

Add Proxy Configuration

In the editor, add the proxy and configuration lines after the existing location blocks or wherever appropriate.

💻 Method 2: Manual SSH Configuration

1

Locate Nginx Configuration File

If you prefer manual editing, SSH into your VPS and open the Nginx configuration file. The location varies based on your OS:

🐧 Debian/Ubuntu

sudo nano /etc/nginx/sites-available/example.com.conf

🎯 CentOS/RHEL

sudo nano /etc/nginx/conf.d/example.com.conf

Replace example.com with your actual domain name.

2

Edit the Server Block

Locate the server { ... } block for your domain. This block typically handles both HTTP and HTTPS traffic.

Add the following lines inside the server block after your root and index directives (adjusting paths and domain as needed):

⚙️ Nginx Configuration Code

📝

Complete Nginx Configuration

Add this configuration inside your server block for V5 Exchange Provider:

# Essential proxy headers
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_set_header X-Forwarded-Port $server_port;
proxy_http_version 1.1;

# Buffer settings for large responses with [id] data
proxy_buffer_size 8k;
proxy_buffers 16 8k;
proxy_busy_buffers_size 16k;

# Enhanced timeouts for [id] parameter queries
keepalive_timeout 30s;
keepalive_requests 1000;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
proxy_send_timeout 300s;

# Header size limits for i18n locales (prevents 502 errors)
large_client_header_buffers 8 64k;
client_header_buffer_size 64k;

# Gzip compression (like DEFLATE)
gzip on;
gzip_types text/plain text/html text/xml text/css 
           application/xml application/xhtml+xml 
           application/rss+xml application/javascript 
           application/x-javascript application/json;

# Proxy to backend for /api/docs
location /api/docs {
    proxy_pass http://localhost:4000/api/docs;
}

# Proxy to backend for /api with WebSocket upgrade
location /api {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://localhost:4000/api;
}

# Frontend proxy
location / {
    proxy_pass http://localhost:3000/;
}
Configuration Notes
  • • You can adjust timeouts and maximum concurrent connections based on your server's performance and expected load
  • • If you need SSL, ensure you have listen 443 ssl http2; and ssl_certificate directives properly set
  • • Make sure your application is running on the specified backend ports (e.g., 3000 for frontend, 4000 for API) before applying these changes

✅ Validate and Restart Nginx

1

Test Configuration

After editing, save the changes and exit the text editor. Run the following command to validate your Nginx configuration:

sudo nginx -t
Expected Output

If successful, you should see: nginx: configuration file /etc/nginx/nginx.conf test is successful

2

Restart Nginx Service

Once the configuration test passes, restart Nginx to apply the changes:

sudo systemctl restart nginx

You can also use sudo service nginx restart on older systems.

🔧 Method 3: WHM Nginx Configuration

WHM

WHM Nginx Config Location

For WHM (Web Host Manager) users, follow these steps:

  1. Go to Service Configuration
  2. Open Nginx Configuration
  3. Select the appropriate Include Editor
  4. Add the Nginx config lines as shown above
  5. Save and reload Nginx
WHM Tip

WHM provides a user-friendly interface for managing Nginx configurations without direct file editing.

🔍 Troubleshooting

❌ Common Issues

  • 502 Bad Gateway: Check if ports 3000 and 4000 are running
  • Configuration Error: Verify syntax with nginx -t
  • Permission Denied: Check file permissions and ownership
  • SSL Issues: Ensure certificates are properly configured

🔧 Useful Commands

  • sudo nginx -s reload - Reload configuration
  • sudo systemctl status nginx - Check service status
  • sudo tail -f /var/log/nginx/error.log - View error logs
  • netstat -tlnp | grep :3000 - Check if app is running

🌍 Optimizing i18n Locales for Header Size

🌐

Reducing Language Headers

If you're still experiencing 502 errors after applying the nginx configuration, your application may have too many languages configured. Next.js generates alternate language headers for every page, and with many languages, these headers can exceed size limits.

Recommended Essential Languages:

NEXT_PUBLIC_LANGUAGES="en,es,fr,de,it,pt,ru,ar,ja,ko,hi,tr"

These 12 languages cover major global markets (~4.5B people) while keeping header sizes manageable.

How to Update:

  1. Edit frontend/next.config.js
  2. Update NEXT_PUBLIC_LANGUAGES to essential languages only
  3. Rebuild frontend: npm run build
  4. Restart application: pm2 restart frontend

🎉 Configuration Complete!

Congratulations! You've successfully updated the Nginx configuration. Your V5 Exchange Provider application should now serve requests via the configured reverse proxy, handle WebSockets, and apply performance optimizations.