Skip to content

Commit 3b0072f

Browse files
committed
Added an verbose example to X-FORWARDED-PREFIX documentation to make its function more clear.
1 parent 8d4bf0e commit 3b0072f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

deployment/proxies.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,24 @@ Reverse proxy in a subpath / subfolder
165165
If you configure the reverse proxy in such a way that the Symfony application is
166166
mapped in a subpath / subfolder instead of the root path of the web host, you will need to
167167
pass the prefix to Symfony by setting the ``X-Forwarded-Prefix`` header.
168-
This is required for Symfony to generate the correct URLs.
169-
170-
This can normally be configured in your reverse proxy configuration.
171-
If the application is served via the reverse proxy under a URL like
172-
``https://localhost/app/``, then ``X-Forwarded-Prefix`` must be set to ``/app/`` by the
173-
reverse proxy. Be sure that ``X-Forwared-Prefix`` is configured as trusted header, if
168+
This is required for Symfony to generate the correct URLs. The header can normally be configured
169+
in your reverse proxy configuration. Be sure that ``X-Forwared-Prefix`` is configured as trusted header, if
174170
you want to use this feature.
175171

172+
The ``X-Forwarded-Prefix`` is used by Symfony to prefix the base URL of request objects, which is
173+
used to generate absolute paths and URLs in Symfony applications. Without the header, the base URL would be only determined
174+
based on the configuration of the web server running Symfony, which leads to incorrect pathes/URLs, when the application
175+
is served under a subpath by a reverse proxy.
176+
177+
For example if your symfony application is directly served under an URL like ``https://symfony.tld/``
178+
and you would like to use a reverse proxy to serve the application under ``https://public.tld/app/``, you would need
179+
to set the ``X-Forwarded-Prefix`` header to ``/app/`` in your reverse proxy configuration.
180+
Without the header, Symfony would generate URLs based on its servers base URL (e.g. ``/my/route``) instead of the correct
181+
``/app/my/route``, which is required to access the route via the reverse proxy.
182+
183+
The header can be different for each reverse proxy, so that access via different reverse proxies served under different
184+
subpaths can be handled correctly.
185+
176186
Custom Headers When Using a Reverse Proxy
177187
-----------------------------------------
178188

0 commit comments

Comments
 (0)