2

I have a server that is using Nginx's 444 to drop connections to undefined hosts:

server {
    listen      80;
    server_name "";
    return      444; 
}

But I can't figure out how to test if it's working.

Here are a few things I've tried, stabbing in the dark:

$ curl -I mysite.com --header 'Host: ""'
HTTP/1.1 301 Moved Permanently

$ curl -I mysite.com --header ''
HTTP/1.1 301 Moved Permanently

I'm trying to get that 444!

Here's the relevant portion of my nginx mysite.conf file

server {
    listen 80;
    server_name "";
    return 444;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

So either I'm testing it wrong, or I'm testing it correctly but the missing host header is still getting captured by my second server block and redirecting.

43Tesseracts
  • 4,617
  • 8
  • 48
  • 94
  • 1
    To check the how your server process requests without HTTP `Host` header you should accrss it by its IP address )) And you trying to config your server incorrect way, [here](https://stackoverflow.com/questions/60362642/nginx-doesnt-listen-on-port-80-twice/60362700#60362700) is working example. – Ivan Shatsky Jun 06 '20 at 17:52
  • Giving you an example: assuming your server has IP address `1.2.3.4` and the domain name it is serving is `example.com`, commands `curl -I example.com` and `curl -I 1.2.3.4 --header 'Host: example.com` are equivalent. – Ivan Shatsky Jun 06 '20 at 18:00
  • You could try: `curl --http1.0` - but I would be surprised if `server_name "";` matches requests without a `Host` header - I would expect Nginx to use the `default_server` instead. – Richard Smith Jun 06 '20 at 19:14

1 Answers1

0

This works with curl 7.47:

curl -I --header Host: mysite.com

Note that the argument to the header option is just Host: ('Host: ' and 'Host: ""' won't work)

Latest versions of curl may have a --http0.9 option that may get you the same result, but I didn't test it.

xhienne
  • 5,738
  • 1
  • 15
  • 34