2023-02-09 00:42:20 +01:00
---
title: Reverse proxy
layout: default
parent: Installation
nav_order: 11
---
# Reverse proxy
If you want to put Part-DB behind a reverse proxy, you have to configure Part-DB correctly to make it work properly.
2023-10-15 13:21:14 +02:00
You have to set the `TRUSTED_PROXIES` environment variable to the IP address of your reverse proxy
(either in your `docker-compose.yaml` in the case of docker, or `.env.local` in case of direct installation).
2023-02-09 00:42:20 +01:00
If you have multiple reverse proxies, you can set multiple IP addresses separated by a comma (or specify a range).
2023-10-15 13:21:14 +02:00
For example, if your reverse proxy has the IP address `192.168.2.10` , your value should be:
2023-02-09 00:42:20 +01:00
```
TRUSTED_PROXIES=192.168.2.10
```
2023-02-28 16:34:51 +01:00
2023-10-15 13:21:14 +02:00
Set the `DEFAULT_URI` environment variable to the URL of your Part-DB installation, available from the outside (so via
2023-11-11 23:03:29 +01:00
the reverse proxy).
2026-07-19 21:40:26 +02:00
You should also set the `TRUSTED_HOSTS` environment variable to a regex matching the host name(s) Part-DB is reachable
under via the reverse proxy, to prevent `HTTP Host header attacks` . For example, if Part-DB is reachable via
2026-07-22 00:29:09 +02:00
`part-db.example.invalid` , set the following in your `.env.local` file (the value must be wrapped in single quotes here):
2026-07-19 21:40:26 +02:00
```
TRUSTED_HOSTS='^(part-db\.example\.invalid)$'
```
2026-07-22 00:29:09 +02:00
If you set `TRUSTED_HOSTS` in your `docker-compose.yaml` instead, the value must **not** be quoted:
```
TRUSTED_HOSTS=^(part-db\.example\.invalid)$
```
2026-07-19 21:40:26 +02:00
See the [configuration options ](../configuration.md ) page for more information about `TRUSTED_HOSTS` .
2023-11-11 23:03:29 +01:00
## Part-DB in a subpath via reverse proxy
If you put Part-DB into a subpath via the reverse proxy, you have to configure your webserver to include `X-Forwarded-Prefix` in the request headers.
For example if you put Part-DB behind a reverse proxy with the URL `https://example.com/partdb` , you have to set the `X-Forwarded-Prefix` header to `/partdb` .
In apache, you can do this by adding the following line to your virtual host configuration:
```
RequestHeader set X-Forwarded-Prefix "/partdb"
```
and in nginx, you can do this by adding the following line to your server configuration:
```
proxy_set_header X-Forwarded-Prefix "/partdb";
```