Search code examples
apacheiplets-encryptrestriction

Apache : Restrict acces to webserver via IP (HTTP/HTTPS)


I run a website on a VPS and I would like to completely block access to the website via The VPS IP Address. I made it work for HTTP but It seems impossible for HTTPS. What I did:

<VirtualHost *:80>
ServerName xxx.xxx.xxx.xxx
Redirect 403 /
DocumentRoot /a/folder/here/
</VirtualHost>

This worked perfectly as expected for http://xx.xx.xx.xx

But I could not find a way to do the same for https://xx.xx.xx.xx

Anyone can help me please?

** I am using:**

Letsencrypt Certificat

Apache 2.4


Solution

  • Just do the same for the virtual host that is bonded to port 443:

    <IfModule mod_ssl.c>
        <VirtualHost *:443>
            ServerName xxx.xxx.xxx.xxx
            Redirect 403 /
            DocumentRoot /a/folder/here/
        </VirtualHost>
    </IfModule>