> ## Documentation Index
> Fetch the complete documentation index at: https://docs.levelrail.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Import nginx configuration

> Convert nginx server blocks into Domain documents with a report that accounts for every directive.

`proxy import nginx` reads nginx configuration on your machine and writes [Domain](https://docs.levelrail.com/iac/resources.md#domain) documents plus a report. It never contacts a server, never runs nginx and never applies anything.

```sh theme={"dark"}
levelrail-cli proxy import nginx /path/to/nginx --out ./iac
levelrail-cli proxy import nginx ./nginx.conf --app www.example.com=web --app 10.0.0.5:9000=billing --strict
```

Pass a main file or a directory (its `nginx.conf`, or every `*.conf` in it). Without `--out` the documents go to stdout and the report to stderr. With `--out` you get one `<host>.yaml` per host, `import-report.md` and `import-report.json`. Existing files are kept unless you pass `--force`.

| Flag | Meaning |
| - | - |
| `--app NAME=APP` | App for a host name, an upstream name or an upstream address. Repeatable. |
| `--prefix DIR` | Directory nginx loaded its files from, so absolute includes map onto yours. Default `/etc/nginx`. |
| `--strict` | Exit non-zero when any directive is unsupported. |
| `--json` | Print the report as JSON. |

## What is converted

| nginx | Result | Status |
| - | - | - |
| `server_name` with exact names | one Domain per name | mapped |
| wildcard, regex or catch all names | nothing | partial or unsupported |
| `proxy_pass http://service` in `location /` | `spec.app` (an app with that name must exist) | mapped |
| `proxy_pass` with a path or `https` | `spec.app`, path or upstream TLS dropped | partial |
| `proxy_pass` to an IP or dotted name | needs `--app` | unsupported without it |
| `upstream` that resolves to one app | `spec.app`; weights and balancing are not imported | partial or unsupported per line |
| `return 301 https://$host$request_uri` | `spec.redirects.forceHttps` | mapped (302 and 307 partial) |
| `return 30x` to another host | `spec.redirect` (the request path is kept) | mapped or partial |
| `add_header`, `proxy_hide_header`, literal `proxy_set_header` | `spec.headers`, following nginx inheritance | mapped |
| `Host`, `X-Real-IP`, `X-Forwarded-*`, websocket upgrade headers, `proxy_http_version` | done by the ingress | mapped |
| `listen 80`, `listen 443 ssl`, `ssl_*` | automatic TLS | mapped or partial |
| other `location` blocks | nothing; add forwarding rules on the domain | unsupported |
| access control, limits, timeouts, `if`, `map`, `rewrite`, file serving, scripting, `stream` | nothing | unsupported |
| process settings such as `worker_processes`, `events`, logs | managed by the platform | partial |

A redirect only host has no backend in nginx, but a Domain needs an app: pass `--app HOST=APP`.

## Read the report before applying

Every directive gets a row with its file, line, status, target and note. Rows hold directive names only, never values. If a host had access control that could not be imported, the report warns and the document starts with a warning comment: set the protection on the domain before you send traffic to it.

## Secrets and safety

* Certificate, key and password files are never opened. Only files matched by `include` are read.
* Headers that look like credentials are not written. Give the value to the app as a secret.
* Includes stay inside the directory of the file you passed. Symlinks are not followed, so for a `sites-enabled` layout include `sites-available` or copy the files.
* Limits come from the environment: `APP_PROXY_IMPORT_MAX_BYTES` (4194304), `APP_PROXY_IMPORT_MAX_FILES` (200), `APP_PROXY_IMPORT_MAX_INCLUDE_DEPTH` (10), `APP_PROXY_IMPORT_MAX_BLOCK_DEPTH` (32).

Then review and run `levelrail-cli stack plan NAME -f ./iac`. If you depend on directives with no equivalent, run nginx as an ordinary app behind the ingress.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.