For the requirements wherein direct access to a website using IP address has to be disabled/blocked, following steps can be followed
To disable/block direct access to IP for port 80 create a new or add to an existing (as required) server configurations as follows
server { listen 80 default_server; server_name _; return 404; }
where _ catches all the domain names pointing to your server’s IP address and the configuration will block all traffic to your IP address (http://YOUR_IP_ADDRESS) by returning the default 404 Not Found Nginx page.
Other NGINX blogs you might find useful
- NGINX – Load Balancing your application made simple
- NGINX – Redirecting traffic between www and non-www domain
- NGINX – Redirecting HTTP to HTTPS
- NGINX – Restrict access to Geographical Locations using GeoIP module
- NGINX – Easiest way to setup SSL on using .pfx files
- NGINX – Understanding and Setting up a reverse proxy server
To disable/block direct access to IP for port 443 use the following in one of your server configurations block
if ($host != "example.com") { return 404; }
example
server { listen 443 ssl; server_name example.com ssl_certificate /etc/nginx/ssl/example.com.crt; ssl_certificate_key /etc/nginx/ssl/example.com.key; if ($host != "example.com") { return 404; } }
this will block all traffic to https://YOUR_IP_ADDRESS
Hope this helps!
works for me, thx!
Good to know it helped!
Thankyou so much.
Glad it helped Suhagiya!
Very useful. Thanks a lot!