User

Custom Nginx Directives

How to add custom Nginx configuration to a specific domain in Opterius Panel.

Last updated 1775606400

Opterius generates Nginx vhost configurations automatically. For most sites this is sufficient, but some applications need additional directives — custom headers, rate limiting, proxy rules, gzip settings, or framework-specific rewrites.

Adding Custom Directives

  1. In Hosting Mode, go to Domains → [domain] → Custom Nginx
  2. Enter your directives in the editor
  3. Click Save

The Agent validates the config with nginx -t before applying it. If there's a syntax error, you'll see the error message and Nginx won't be reloaded — your site stays up.

Where Directives Are Inserted

Your custom directives are injected inside the server {} block for your domain, after the standard configuration. This gives you access to everything you'd normally add in a vhost block.

Examples

Add security headers:

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
add_header Referrer-Policy "strict-origin-when-cross-origin";

Enable gzip for a specific domain:

gzip on;
gzip_types text/plain text/css application/json application/javascript;
gzip_min_length 1000;

Rate limit an API endpoint:

location /api/ {
    limit_req zone=api burst=20 nodelay;
}

Proxy to a Node.js app running on port 3000:

location / {
    proxy_pass http://127.0.0.1:3000;
    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;
}

Laravel-style try_files (if not already set by the panel):

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

[!NOTE] Opterius already sets up try_files for PHP sites. If your custom directives conflict with the generated config, check the full vhost by SSH-ing into the server and reviewing /etc/nginx/sites-available/{domain.com}.conf.

Resetting Custom Directives

To remove all custom directives, clear the editor and save. The vhost returns to the default generated configuration.

Next Steps