how to block ip public access to my API / Web App

How do I block access to my API / Web App through the public ip of my droplet?

I am using Apache and PHP.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.


You could use an .htaccess deny from all rule. For example:

order deny,allow
deny from all
allow from YOUR_IP_HERE

The rule above would deny the access to your site for everyone except your IP address.

If this does not work for any reason, make sure that you’ve got AllowOverride enabled:

Regards, Bobby

Hi @brdaniellima,

f you are using Name based virtual hosts, you may want to simply block any bots etc that try to access your server by direct IP address. It’s unlikely a real user would try to hit your server by using the actual IP address.

To do this, you can use this Virtual Host config:

<VirtualHost *:80>
    Redirect 403 /
    ErrorDocument 403 "No"
    DocumentRoot /dev/null/
    UseCanonicalName Off
    UserDir disabled

Of course, please change the IP to the real server IP address(es)

And that’s it, anyone trying to hit the server by IP address will get a simple 403 error.