Laravel generates wrong route behind reverse proxy with path prefix

762 Views Asked by At

Running Laravel behind Traefik as reverse proxy, with a Path Prefix (eg /api/ => Laravel).

Laravel is served by Nginx and Php-fpm.

Laravel use Symfony HTTP foundation to generate route URL.

Symfony is not seeing correctly the base path, and generate URL without /api/ prefix.

As a dirty workaround, I fixed it by doing as the 1st line on index.php:

$_SERVER['SCRIPT_NAME'] = '/api/' . $_SERVER['SCRIPT_NAME'];

How can I force the full URL or the base path?

1

There are 1 best solutions below

0
Thomas Decaux On

This was fixed by Symfony team, for Symfony 5.2:

my original issue: https://github.com/symfony/symfony/issues/36809

the PR: https://github.com/symfony/symfony/pull/37734