By Daniel Lima
How do I block access to my API / Web App through the public ip of my droplet?
I am using Apache and PHP.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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>
ServerName 123.123.123.123
Redirect 403 /
ErrorDocument 403 "No"
DocumentRoot /dev/null/
UseCanonicalName Off
UserDir disabled
</VirtualHost>
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.
Hello,
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:
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file
Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.