Eu tenho uma configuração de virtualhost do meu servidor Apache:
<VirtualHost *:80>
DocumentRoot "/app/www"
ServerName myhostname
<Directory "/app/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Eu quero permitir o acesso apenas solicitações com myhostname
o nome do host. Mas eu quero negar todas as outras solicitações feitas por hostname ou server-ip:
http://myhostiname/ ALLOW
http://1.2.3.4/ (this is one of the server ip addresses) DENY
Minha configuração de virtualhost funciona conforme o esperado.
Agora eu tenho que editar a configuração para permitir que o usuário acesse um determinado caminho por ip porque um cliente não pode resolver o nome do host local.
Isto é um exemplo:
http://myhostiname ALLOW
http://1.2.3.4/ DENY
http://1.2.3.4/any/path DENY
http://1.2.3.4/allowed/path ALLOW
http://1.2.3.4/allowed/path/subpath ALLOW
Eu tentei o <Location>
elemento em um novo virtualhost:
<VirtualHost 0.0.0.0:80>
DocumentRoot "/app/www"
<Directory "/app/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Location "/">
AllowOverride None
Order Deny,Allow
Deny from all
</Location>
<Location "^/allowed">
Allow from all
</Location>
</VirtualHost>
Mas isso nega tudo, exceto as solicitações de nome de host. O que estou perdendo?
Eu dividiria sua configuração de vhost em dois ou mais vhosts. É possível fazer tudo em um vhost, mas acho as configurações "separadas" mais fáceis de ler e registrar.