I have a managed Digital Ocean load balancer which works well directing traffic between two droplets.
However if I access the IP address in the browser like this: https://xx.xxx.xx.xxx/ I receive an nginx 404 error and SSL cert warning.
This has been raised on a security audit. I want to disallow any access to the load balancer through the IP address and only allow access through the domain.
Any ideas would be appreciated. Many thanks, Matthew
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!
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.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Heya,
You may consider setting up your DNS records so that your website can only be accessed via the domain name. This configuration deploys the Domain Name System (DNS) to resolve your site’s domain name to the IP address of your load balancer, hence rendering direct IP access non-permissible.
Please do note that this might not entirely prevent someone from bypassing DNS and directly accessing your site via the IP, however, they will encounter the SSL warning because the SSL certificate is issued for your domain and not for your IP address.
You can find more details about setting up DNS here: DigitalOcean DNS Documentation
I hope that this helps!
Hi Matthew,
Currently you can’t restrict the direct access to the IP address of your load balancer directly, but in this case, you can do that on the Droplet level by configuring your application or web server (NGINX in this case) to only respond to requests made to the domain name, and to ignore any requests made directly to the IP address.
Here is an example of how you can do this in NGINX:
The first
server
block listens for requests without aHost
header or with aHost
header which doesn’t match any otherserver
blocks. It responds to such requests with a 444 status code, which tells NGINX to close the connection immediately.The second
server
block listens for requests that are made toyourdomain.com
orwww.yourdomain.com
. It will handle these requests according to the configuration specified in that block.You can do the same thing for port 443 as well:
Let me know how it goes!
Best,
Bobby