# Custom nginx configuration

> Add custom nginx server directives to your PHP applications for advanced configuration needs.

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

1. Navigate to your application in the Ploi Cloud dashboard
2. Go to the "Security" tab
3. Expand the "Custom nginx configuration" section
4. Enter your nginx directives in the text area
5. Save your settings
6. Deploy your application to apply the changes

### Example configurations

**Custom location block for an API endpoint:**

```nginx
location /api/special {
    proxy_pass http://backend;
}
```

**Return a custom response:**

```nginx
location /health {
    return 200 'OK';
}
```

**Custom cache headers for static files:**

```nginx
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 platform
  - `listen`, `server_name`, `root` - core server configuration
  - `include` - file inclusion not allowed
  - `ssl_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](https://nginx.org/en/docs/).
