# Custom nginx configuration

> Add your own nginx directives to a site — WebSockets, pretty URLs, redirects, headers, timeouts — safely.

Some apps need extra web server configuration: WebSockets for real-time features, pretty URLs, larger uploads, redirects or extra headers. On servers running **nginx**, the site's **nginx** pane lets you add your own directives to its server block.

## Add directives

1. Open the site and choose **nginx**.
2. Write your directives in the editor, or start from an example: **WebSockets**, **Pretty URLs**, **Large uploads**, **Redirect**, **Security headers**.
3. Click **Apply** and approve with your passkey.

Before the new configuration goes live, nginx checks it (`nginx -t`). If the check fails, the previous configuration stays active and the pane says why. Leave the editor empty and apply to remove your directives.

## Examples

WebSockets to an app listening on a local port (Laravel Reverb, Socket.IO…):

```nginx
location /app {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 3600s;
}
```

Pretty URLs (every unknown path goes to `index.php`):

```nginx
location / {
    try_files $uri $uri/ /index.php?$args;
}
```

A redirect and larger uploads:

```nginx
rewrite ^/old-blog/(.*)$ /blog/$1 permanent;
client_max_body_size 512m;
fastcgi_read_timeout 600s;
```

## What is allowed

Your directives run inside nginx, which runs as root, so only site-level directives are accepted:

- **Allowed**: `location` and `if` blocks, `rewrite`, `return`, `try_files`, `set`, `error_page`, headers (`add_header`, `expires`), `proxy_*` (to `http://` or `https://` addresses), `fastcgi_*` for this site's own PHP pool, timeouts, body sizes, `gzip`, `sub_filter`, `allow`/`deny`, `limit_rate`.
- **Refused**: `include`, `root`, `alias`, `load_module`, embedded languages (Lua, Perl, njs), certificates, log files written elsewhere, `proxy_pass` to unix sockets — anything that could reach outside the site.

A `location /` (or `@app` for app sites) of your own replaces the site's default one, so you can change how unknown paths are handled.

## OpenLiteSpeed

On OpenLiteSpeed servers the **nginx** pane is not shown: put rewrite rules in the site's `.htaccess` file, which OpenLiteSpeed reads.

---
Source: https://zefily.com/docs/custom-nginx
