From 4d94af15b66f2b01645ba9324f22b55e74eb8ef0 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 22 Feb 2024 16:22:21 +0100 Subject: [PATCH] Minor tweaks --- deployment/proxies.rst | 44 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/deployment/proxies.rst b/deployment/proxies.rst index f3ed2bd0fba..0fdb3fd9350 100644 --- a/deployment/proxies.rst +++ b/deployment/proxies.rst @@ -162,25 +162,31 @@ trusted proxies. Reverse proxy in a subpath / subfolder -------------------------------------- -If you a running a Symfony application behind a reverse proxy, where the application is served in a subpath / subfolder, -you might encounter the problem that Symfony generates incorrect URLs, which ignore the subpath / subfolder of the reverse proxy. -To fix this, you need to pass the subpath / subfolder route prefix of the reverse proxy to Symfony by -setting the ``X-Forwarded-Prefix`` header. This is required for Symfony to generate the correct URLs. The header can normally be configured -in your reverse proxy configuration. Configure ``X-Forwared-Prefix`` as trusted header to be able to use this feature. - -The ``X-Forwarded-Prefix`` is used by Symfony to prefix the base URL of request objects, which is -used to generate absolute paths and URLs in Symfony applications. Without the header, the base URL would be only determined -based on the configuration of the web server running Symfony, which leads to incorrect pathes/URLs, when the application -is served under a subpath by a reverse proxy. - -For example if your symfony application is directly served under an URL like ``https://symfony.tld/`` -and you would like to use a reverse proxy to serve the application under ``https://public.tld/app/``, you would need -to set the ``X-Forwarded-Prefix`` header to ``/app/`` in your reverse proxy configuration. -Without the header, Symfony would generate URLs based on its servers base URL (e.g. ``/my/route``) instead of the correct -``/app/my/route``, which is required to access the route via the reverse proxy. - -The header can be different for each reverse proxy, so that access via different reverse proxies served under different -subpaths can be handled correctly. +If your Symfony application runs behind a reverse proxy and it's served in a +subpath/subfolder, Symfony might generate incorrect URLs that ignore the +subpath/subfolder of the reverse proxy. + +To fix this, you need to pass the subpath/subfolder route prefix of the reverse +proxy to Symfony by setting the ``X-Forwarded-Prefix`` header. The header can +normally be configured in your reverse proxy configuration. Configure +``X-Forwared-Prefix`` as trusted header to be able to use this feature. + +The ``X-Forwarded-Prefix`` is used by Symfony to prefix the base URL of request +objects, which is used to generate absolute paths and URLs in Symfony applications. +Without the header, the base URL would be only determined based on the configuration +of the web server running Symfony, which leads to incorrect paths/URLs, when the +application is served under a subpath/subfolder by a reverse proxy. + +For example if your Symfony application is directly served under a URL like +``https://symfony.tld/`` and you would like to use a reverse proxy to serve the +application under ``https://public.tld/app/``, you would need to set the +``X-Forwarded-Prefix`` header to ``/app/`` in your reverse proxy configuration. +Without the header, Symfony would generate URLs based on its server base URL +(e.g. ``/my/route``) instead of the correct ``/app/my/route``, which is +required to access the route via the reverse proxy. + +The header can be different for each reverse proxy, so that access via different +reverse proxies served under different subpaths/subfolders can be handled correctly. Custom Headers When Using a Reverse Proxy -----------------------------------------