block access by the server's IP number so that access is made only through VirtualHosts domains

0

I am using virtual hosts in apache 2.4, when accessing the web server by the IP of the server, it is called the first virtual host of the list, how to block access by the IP number of the server so that access is made only by the VirtualHosts domains.

    
asked by anonymous 31.01.2018 / 12:33

1 answer

0

Testing the apache's if and else policies I found a palliative solution for virtualHost that is responding to the server IP.

<VirtualHost *:80>

    ServerAdmin [email protected]
    ServerName exemplo.com

    ServerAlias www.exemplo.com
    DocumentRoot /var/www/exemplo.com/public_html


    # bloqueando acesso pelo IP do servidor, senao redireciona para o site
    <If "tolower(%{SERVER_NAME}) == '192.168.1.100'">
            AllowOverride None
            Require all denied
    </If>
    <ElseIf "tolower(%{SERVER_NAME}) != 'www.exemplo.com'">
            Redirect permanent "/" "http://www.exemplo.com/"
    </ElseIf>


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost> 
    
31.01.2018 / 15:07