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

# Nginx

> NGINX can be automatically configured by Devbox via the built-in NGINX Plugin. This plugin will activate automatically when you install NGINX using `devbox add nginx`.

[**Example Repo**](https://github.com/jetify-com/devbox/tree/main/examples/servers/nginx)

## Adding NGINX to your Shell[​](#adding-nginx-to-your-shell "Direct link to Adding NGINX to your Shell")

Run `devbox add nginx`, or add the following to your `devbox.json`

```json theme={null}
  "packages": [
    "nginx@latest"
  ]
```

This will install the latest version of NGINX. You can find other installable versions of NGINX by
running `devbox search nginx`. You can also view the available versions on
[Nixhub](https://www.nixhub.io/packages/nginx)

## NGINX Plugin Details[​](#nginx-plugin-details "Direct link to NGINX Plugin Details")

### Services[​](#services "Direct link to Services")

* nginx

Use `devbox services start|stop nginx` to start and stop the NGINX service in the background

### Helper Files[​](#helper-files "Direct link to Helper Files")

The following helper files will be created in your project directory:

* devbox.d/nginx/nginx.conf
* devbox.d/nginx/nginx.template
* devbox.d/nginx/fastcgi.conf
* devbox.d/web/index.html

Devbox uses
[envsubst](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html) to
generate `nginx.conf` from the `nginx.template` file every time Devbox starts a shell, service, or
script. This allows you to create an NGINX config using environment variables by modifying
`nginx.template`. To edit your NGINX configuration, you should modify the `nginx.template` file.

Note that by default, NGINX is configured with `./devbox.d/web` as the root directory. To change
this, you should modify `./devbox.d/nginx/nginx.template`

### Environment Variables[​](#environment-variables "Direct link to Environment Variables")

```bash theme={null}
NGINX_CONFDIR=devbox.d/nginx/nginx.conf
NGINX_PATH_PREFIX=.devbox/virtenv/nginx
NGINX_TMPDIR=.devbox/virtenv/nginx/temp
```

### Notes[​](#notes "Direct link to Notes")

You can easily configure NGINX by modifying these env variables in your shell's `init_hook`

To customize:

* Use \$NGINX\_CONFDIR to change the configuration directory
* Use \$NGINX\_LOGDIR to change the log directory
* Use \$NGINX\_PIDDIR to change the pid directory
* Use \$NGINX\_RUNDIR to change the run directory
* Use \$NGINX\_SITESDIR to change the sites directory
* Use $NGINX_TMPDIR to change the tmp directory. Use $NGINX\_USER to change the user
* Use \$NGINX\_GROUP to customize.

You can also customize the `nginx.conf` and `fastcgi.conf` stored in `devbox.d/nginx`

### Disabling the NGINX Plugin[​](#disabling-the-nginx-plugin "Direct link to Disabling the NGINX Plugin")

You can disable the NGINX plugin by running `devbox add nginx --disable-plugin`, or by setting the
`disable_plugin` field in your `devbox.json`:

```json theme={null}
{
  "packages": {
    "nginx": {
      "version": "latest",
      "disable_plugin": true
    }
  }
}
```

[Edit this page](https://github.com/jetify-com/docs/tree/main/docs/devbox/devbox-examples/servers/nginx/index.mdx)
