# Self-host Nginx

> The Nginx web server on the official Alpine image, serving a persistent web root. It starts with the default welcome page; put your site files in the web root volume through the app's Files.

- Page: https://levelrail.com/templates/nginx/
- JSON: https://levelrail.com/templates/nginx.json
- Category: Infrastructure
- Licence: BSD-2-Clause (Permissive license)
- Source: https://github.com/nginx/nginx
- Upstream docs: https://nginx.org/en/docs/

## Requirements
- Memory: about 64 MiB
- amd64: unknown, arm64: unknown
- Needs configuration before start: no
- Pinned image tag: 1.27.2-alpine

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| nginx | nginx | 1.27.2-alpine | 80 | nginx_html -> /usr/share/nginx/html |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| nginx | TZ | preset |

## Deploy

### CLI

```bash
levelrail-cli templates install nginx --name my-nginx
```

Add --domain SERVICE=HOST to serve a service on your own domain, for example --domain nginx=app.example.com.

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  https://levelrail.example.com/api/v1/service-templates/nginx/install \
  -d '{
    "name": "my-nginx"
  }'
```

Create a token in the dashboard first. Name, env and domains are the request fields.

## First run
1. Open the address to see the welcome page, then replace the files in /usr/share/nginx/html with your site.

## Questions

### Can I deploy Nginx on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list has an entry with the id nginx for this app, so check that entry as well. Dokku deploys container images with its own commands, so the pinned image nginx:1.27.2-alpine is what you deploy there.

Self-host Nginx, Nginx docker compose file, deploy Nginx on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
