Verifique se HostnameLookups está definido como Off
no Apache.
Você diz que o servidor está executando o Apache, correto? Bem, se esse for o caso, abra httpd.conf
ou apache2.conf
(tudo depende de como ele foi instalado na sua configuração; ambos os arquivos são basicamente os mesmos) e procure por uma linha de configuração com HostnameLookups
nela. Por padrão, HostnameLookups
é definido como Off
conforme explicado no comentário que deve estar acima da configuração HostnameLookups
nesse arquivo; ênfase ousada é minha:
HostnameLookups: Log the names of clients or just their IP addresses e.g., www.apache.org (on) or 204.62.129.132 (off). The default is off because it'd be overall better for the net if people had to knowingly turn this feature on, since enabling it means that each client request will result in AT LEAST one lookup request to the nameserver.
E a documentação oficial do Apache entra em detalhes também; mais uma vez a ênfase ousada é minha:
The default is Off in order to save the network traffic for those sites that don't truly need the reverse lookups done. It is also better for the end users because they don't have to suffer the extra latency that a lookup entails. Heavily loaded sites should leave this directive Off, since DNS lookups can take considerable amounts of time.
Não use nomes de host para as diretivas Allow from
/ Deny from
.
Além disso, você tem diretórios ou diretivas que usam o Apache Basic Auth? Qual é a proteção de senha que pode ser definida no Apache? Lembro-me de que, em alguns casos, havia lentidão relacionada a pesquisas de nome de host conectadas a campos Allow from
, como Allow from localhost
. Comentar o Allow from localhost
ou definir isso para Allow from 127.0.0.1 ::1
e, em seguida, reiniciar o Apache esclareceria isso.
Como explicado em a documentação oficial do Apache , mesmo com HostnameLookups
definido como Off
usando nomes de host completos nas diretivas Allow from
/ Deny from
acionará uma cadeia inteira de pesquisas de DNS que podem diminuir o acesso; ênfase ousada é minha:
Hosts whose names match, or end in, this string are allowed access. Only complete components are matched, so the above example will match foo.apache.org but it will not match fooapache.org. This configuration will cause Apache to perform a double reverse DNS lookup on the client IP address, regardless of the setting of the HostnameLookups directive. It will do a reverse DNS lookup on the IP address to find the associated hostname, and then do a forward lookup on the hostname to assure that it matches the original IP address. Only if the forward and reverse DNS are consistent and the hostname matches will access be allowed.
Esta postagem no blog também explica bem se você se importa leia mais detalhes sobre como as entradas Allow from
/ Deny from
que têm um nome de host - em vez de um endereço IP bruto - podem retardar o acesso do Apache devido a várias pesquisas de DNS:
However, I recently came across a situation where we inadvertently were doing the equivalent without explicitly enabling HostnameLookups. How? By limiting access based on the remote hostname! Read the documentation on the Allow directive, under the section "A (partial) domain-name":
This configuration will cause Apache to perform a double reverse DNS lookup on the client IP address, regardless of the setting of the HostnameLookups directive. It will do a reverse DNS lookup on the IP address to find the associated hostname, and then do a forward lookup on the hostname to assure that it matches the original IP address. Only if the forward and reverse DNS are consistent and the hostname matches will access be allowed. This makes perfect sense, but it is a pretty big likely unexpected side effect to using something like:
Allow from .example.com
In our case it was an even less obvious case that didn't make us think of hostnames at all:
Allow from localhost
Here localhost was written, perhaps to save some effort or maybe increase clarity vs. writing out 127.0.0.1 (IPv4) and ::1 (IPv6). Mentally it's so easy to view "localhost" is a direct alias for 127.0.0.1 and ::1 that we can forget that the name "localhost" is just a convention, and requires a lookup like any other name. Those familiar with the MySQL database may know that it actually assigns special confusing meaning to the word "localhost" to make a UNIX socket connection instead of a TCP connection to 127.0.0.1 or whatever "localhost" is defined as on the system!
You may also be thinking that looking up 127.0.0.1 is fast because that is usually mapped to "localhost" in /etc/hosts. True, but every other visitor who is not in /etc/hosts gets the slow DNS PTR lookup instead! And depending on the operating system, you may see "ip6-localhost" or "ip6-loopback" (Debian 7, Ubuntu 12.04), "localhost6" (RHEL 5/6, Fedora 19) in /etc/hosts, or something else. So it's important to spell out the addresses:
Allow from 127.0.0.1 Allow from ::1
Doing so immediately stops the implicit HostnameLookups behavior and speeds up the website. In this case it wasn't a problem, since it was for a private, internal website that couldn't be visited at all by anyone not first allowed through a firewall, so traffic levels were relatively low. That access control is part of why localhost needed to be allowed in the first place. But it would have been very bad on a public production system due to the slowdown in serving traffic.