-1

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?

Flipper
  • 99
  • 3
  • 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 Answers2

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

Dom
  • 6,628
  • 1
  • 19
  • 24
0
<Location /warname>
                SetEnvIF X-Forwarded-For "(,| |^)11\.11\.111\.111(,| |$)" DenyIP
                Order allow,deny
                Deny from env=DenyIP
                Allow from all
        </Location>
CustomLog /opt/apache/logs/DenyIP_access.log common env=DenyIP
Jenny D
  • 27,358
  • 21
  • 74
  • 110