Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to capture all requests to arbitrary sub-domains which do not have a virtual host setup, and redirect to a custom 404 page in nginx? I will have a wild card A record setup * and all our users will have a sub-domain If someone enters a sub-domain which does not exist how can I redirect to a custom 404 page rather than have it resolve since wild card is setup?

share|improve this question
up vote 1 down vote accepted

Sure - though I'm not sure what you mean by "rather than have it resolve" - hopefully you don't mean preventing DNS resolution, as that's not possible from your web server.

You'll want something like this:

server {
  server_name _;
  listen 80 default_server;
  error_page 404;
  return 404;
share|improve this answer
No what I meant was that I think with wild card A records with some configurations between the server and DNS that people going to random sub-domains end up at your home page – Anagio Nov 21 '11 at 6:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.