Custom nginx configuration
2 min read
Updated 1 month ago
Custom nginx configuration
For advanced use cases, you can add custom nginx server directives to your application. This feature is available for PHP-based applications using the PHP-FPM + Nginx runtime.
Supported application types
Custom nginx configuration is available for:
- Laravel applications (with PHP-FPM + Nginx)
- PHP applications (with PHP-FPM + Nginx)
- Statamic applications (with PHP-FPM + Nginx)
- Craft CMS applications (with PHP-FPM + Nginx)
This feature is not available for:
- WordPress applications
- Node.js applications
- Applications using FrankenPHP (Octane)
Adding custom configuration
- Navigate to your application in the Ploi Cloud dashboard
- Go to the "Security" tab
- Expand the "Custom nginx configuration" section
- Enter your nginx directives in the text area
- Save your settings
- Deploy your application to apply the changes
Example configurations
Custom location block for an API endpoint:
location /api/special {
proxy_pass http://backend;
}
Return a custom response:
location /health {
return 200 'OK';
}
Custom cache headers for static files:
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
Validation rules
Your configuration is validated before saving. The following restrictions apply:
- Forbidden directives: Certain directives cannot be used as they are managed by the platform or not available:
location /- the root location block is already configured by the platformlisten,server_name,root- core server configurationinclude- file inclusion not allowedssl_certificate,ssl_certificate_key,ssl_trusted_certificate,ssl_client_certificate- SSL is managed automatically- Lua and Perl scripting directives - scripting modules are not available
- Balanced braces: All opening braces
{must have matching closing braces} - Maximum length: Configuration is limited to 65,535 characters
If validation fails, you'll see an error message explaining the issue.
Important notes
- Changes require a new deployment to take effect
- Incorrect syntax may cause deployment failures
- Test your configuration thoroughly before deploying to production
- If a deployment fails due to nginx configuration errors, remove or fix the custom configuration and deploy again
For detailed nginx documentation, see the official nginx documentation.