1

I am trying to catch all traffic not caught by a sites-enabled configuration file, and instead of throwing the default 404, to instead throw a 200 with a blank response instead.

So, for example, if my site is https://www.example.com at ip x.x.x.x and somebody maps https://www.bad.com to my ip at x.x.x.x they would simply get a 200 with a blank content.

To accomplish this, I have a file located at /var/www/index.html that is a blank file, and have the following rule set up in {nginxdir}/conf.d/200catchall.conf which is imported in the standard {nginxdir}/nginx.conf file:

# Serve blank page to any requests not intended for one of our servers
server {
       listen 443;
       server_name _;
       location / {
                root /var/www
       }
}

This works great for rendering the 200 blank screen for a request to https://www.bad.com. However, it tries to traverse the directory when something like https://www.bad.com/cgibin/nofile.php is requested, and ends up throwing an error to error.log and results ultimately in a 404.

I've also attempted to replace the root directive with a try_files /var/www/index.html directive, which seems to give the same result...

Have been pulling my hair out for a while on this - any advice?

matt
  • 688
  • 7
  • 15

2 Answers2

4

To avoid sending any content back, minimal load for your server, return a 204 No Content response instead. See Wikipedia Entry.

server {
  listen 80 default_server;
  listen 443 ssl default_server;

  return 204;
}

An alternative approach to setting up a catch all server is described here.

Community
  • 1
  • 1
Dayo
  • 12,413
  • 5
  • 52
  • 67
  • This is what ultimately helped me. I'm using a 204 for all requests that aren't intended for my server. Thanks! – matt Sep 30 '14 at 19:43
1

Simplest catch-all looks like this:

server {
  listen 80 default_server;
  listen 443 ssl default_server;

  return 200;
}
Alexey Ten
  • 13,794
  • 6
  • 44
  • 54
  • Thanks for the quick response Alexey...problem is that if I get a request for most file formats other than *.html (e.g. `https://www.bad.com/flarg/blarf.zip`), the browser actually downloads the response as that filetype, rather than rendering a blank html page...any advice? – matt Sep 26 '14 at 22:34