```console
-$ fastapi run main.py --root-path /api/v1
+$ fastapi run main.py --forwarded-allow-ips="*" --root-path /api/v1
: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
@@ -224,7 +321,7 @@ And now start your app, using the `--root-path` option:
```console
-$ fastapi run main.py --root-path /api/v1
+$ fastapi run main.py --forwarded-allow-ips="*" --root-path /api/v1
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
diff --git a/docs/en/docs/deployment/https.md b/docs/en/docs/deployment/https.md
index b52ed40c8..a249a3672 100644
--- a/docs/en/docs/deployment/https.md
+++ b/docs/en/docs/deployment/https.md
@@ -190,6 +190,38 @@ To do that, and to accommodate different application needs, there are several wa
All this renewal process, while still serving the app, is one of the main reasons why you would want to have a **separate system to handle HTTPS** with a TLS Termination Proxy instead of just using the TLS certificates with the application server directly (e.g. Uvicorn).
+## Proxy Forwarded Headers { #proxy-forwarded-headers }
+
+When using a proxy to handle HTTPS, your **application server** (for example Uvicorn via FastAPI CLI) doesn't known anything about the HTTPS process, it communicates with plain HTTP with the **TLS Termination Proxy**.
+
+This **proxy** would normally set some HTTP headers on the fly before transmitting the request to the **application server**, to let the application server know that the request is being **forwarded** by the proxy.
+
+/// note | Technical Details
+
+The proxy headers are:
+
+*
X-Forwarded-For
+*
X-Forwarded-Proto
+*
X-Forwarded-Host
+
+///
+
+Nevertheless, as the **application server** doesn't know it is behind a trusted **proxy**, by default, it wouldn't trust those headers.
+
+But you can configure the **application server** to trust the *forwarded* headers sent by the **proxy**. If you are using FastAPI CLI, you can use the *CLI Option* `--forwarded-allow-ips` to tell it from which IPs it should trust those *forwarded* headers.
+
+For example, if the **application server** is only receiving communication from the trusted **proxy**, you can set it to `--forwarded-allow-ips="*"` to make it trust all incoming IPs, as it will only receive requests from whatever is the IP used by the **proxy**.
+
+This way the application would be able to know what is its own public URL, if it is using HTTPS, the domain, etc.
+
+This would be useful for example to properly handle redirects.
+
+/// tip
+
+You can learn more about this in the documentation for [Behind a Proxy - Enable Proxy Forwarded Headers](../advanced/behind-a-proxy.md#enable-proxy-forwarded-headers){.internal-link target=_blank}
+
+///
+
## Recap { #recap }
Having **HTTPS** is very important, and quite **critical** in most cases. Most of the effort you as a developer have to put around HTTPS is just about **understanding these concepts** and how they work.
diff --git a/docs_src/behind_a_proxy/tutorial001_01.py b/docs_src/behind_a_proxy/tutorial001_01.py
new file mode 100644
index 000000000..52b114395
--- /dev/null
+++ b/docs_src/behind_a_proxy/tutorial001_01.py
@@ -0,0 +1,8 @@
+from fastapi import FastAPI
+
+app = FastAPI()
+
+
+@app.get("/items/")
+def read_items():
+ return ["plumbus", "portal gun"]
diff --git a/tests/test_tutorial/test_behind_a_proxy/test_tutorial001_01.py b/tests/test_tutorial/test_behind_a_proxy/test_tutorial001_01.py
new file mode 100644
index 000000000..f13046e01
--- /dev/null
+++ b/tests/test_tutorial/test_behind_a_proxy/test_tutorial001_01.py
@@ -0,0 +1,21 @@
+from fastapi.testclient import TestClient
+
+from docs_src.behind_a_proxy.tutorial001_01 import app
+
+client = TestClient(
+ app,
+ base_url="https://example.com",
+ follow_redirects=False,
+)
+
+
+def test_redirect() -> None:
+ response = client.get("/items")
+ assert response.status_code == 307
+ assert response.headers["location"] == "https://example.com/items/"
+
+
+def test_no_redirect() -> None:
+ response = client.get("/items/")
+ assert response.status_code == 200
+ assert response.json() == ["plumbus", "portal gun"]