app.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. /**
  4. * @var \Symfony\Component\ClassLoader\ClassLoader
  5. */
  6. $loader = require __DIR__.'/../app/autoload.php';
  7. $kernel = new AppKernel('prod', false);
  8. if (PHP_VERSION_ID < 70100) {
  9. if (in_array($_SERVER['REMOTE_ADDR'], ['144.217.203.53', '54.38.136.239', '54.37.131.18', '142.44.164.249', '142.44.164.255', '54.37.2.184', '139.99.121.122', '54.37.4.73', '51.38.227.34'], true)) {
  10. Request::setTrustedProxies([$_SERVER['REMOTE_ADDR']]);
  11. // force all trusted header names
  12. Request::setTrustedHeaderName(Request::HEADER_FORWARDED, '');
  13. Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X_REAL_IP');
  14. Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, '');
  15. Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, '');
  16. Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, '');
  17. }
  18. } else {
  19. Request::setTrustedProxies(
  20. // remote_addr is set to the correct client IP but we need to mark it trusted so that Symfony picks up the X-Forwarded-Host,
  21. // X-Forwarded-Port and X-Forwarded-Proto headers correctly and sees the right request URL
  22. [$_SERVER['REMOTE_ADDR']],
  23. // Use all X-Forwarded-* headers except X-Forwarded-For as nginx handles the IP computation
  24. Request::HEADER_X_FORWARDED_AWS_ELB ^ Request::HEADER_X_FORWARDED_FOR
  25. );
  26. }
  27. $request = Request::createFromGlobals();
  28. $response = $kernel->handle($request);
  29. $response->send();
  30. $kernel->terminate($request, $response);