nginx_deny_host_headers

Nginx deny illegal host headers

My friend was ask me about preventing the IP address of Virtual Host from be accessed directly from web browser. The goals of this setup is deny the ilegal host headers that was sent by web browser. As an example, I’ve domain blog.pnyet.web.id with IP address 111.68.119.146 and I wanna reject all queries to 111.68.119.146 from web browser. Please see below for details:

if ($host !~* ^(yourdomain.com|www.yourdomain.com)$ ) {
return 444;
}

For an example setup in this blog:

server {
listen blog.pnyet.web.id:80;
server_name blog.pnyet.web.id www.blog.pnyet.web.id;
if ($host !~* ^(blog.pnyet.web.id|www.blog.pnyet.web.id)$ ) {
return 444;
}

Hope this help

Leave a Reply

Your email address will not be published. Required fields are marked *


*