Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 *.example.com and all our users will have a sub-domain username.example.com. 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

1 Answer 1

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 http://your.site.com/prettyerrorpage.html;
  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

 
discard

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.