17

There's a way to per-process override name resolution process-local override of name resolution? using HOSTALIASES. Do you think it's applicable to PHP-FPM workers too? I have this line in /etc/php-fpm.d/www.conf:

env[HOSTALIASES] = /etc/hosts.php-fpm

And when I examine $_SERVER, I see HOSTALIASES, but the actual override in the hosts.php-fpm (127.0.0.1 example.com) is not effective, it's returned from the nameservers. Do you have a suggestion on how to make (a similar solution) work?

Community
  • 1
  • 1
Aron Novak
  • 314
  • 1
  • 14

1 Answers1

1

You're trying to use HOSTALIASES in the wrong way. To be respected, alias should meet 2 requirements:

  1. should not contain dots (here is code which, I believe, checks it). That is mentioned in man of hostname(7)
  2. target should be complete hostname. That is also mentioned in hostname doc.

So, your record in HOSTALIASES should look like

example someexample.com

In case you need to alias the ip, you can use something like xip.io

Generally, that should work with any php function which relies on gethostbyname (that also true for php-fpm).

Evgeny Soynov
  • 704
  • 3
  • 13