I am trying to block people from accessing my server via my ip address. Ideally I would like them to only be able to access it using my domain name. I have searched Google and unable to find anything. Is there a way to do this in nginx and/or Apache?
Asked
Active
Viewed 1,380 times
-1
-
In Nginx, create a server block with a `server_name yourdomain.com;` (and include the relevant location blocks, etc.). Create a second server block with a `listen 80 default_server;` and `server_name _;` and a single location block (e.g. `location / { deny all; }`). The first server block will only match requests to your domain, all other requests (IP, invalid domain, etc.) will be handled by the default server block (which will deny the request). – cyberx86 Aug 01 '13 at 05:21
2 Answers
0
On Apache2, create a VirtualHost based on the name of the domain, and an other without nameServer option (which means all names not found in the configuration, like IP). The default should be the first loaded by Apache2.
You can do redirects from default to domain, or serve what page you want as it is separated from your domain VirtualHost
![](../../users/profiles/15454.webp)
Dom
- 6,628
- 1
- 19
- 24