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

For a set of VPSes operated by my company, I'd like to get a list of domain names hosted by each. The list of names has grown in an ad-hoc way for a few years. Is there a simple way to query the Apache and/or Nginx configurations to see what domains the server answers to on port 80?

It is safe to assume (a) that I have sudo on these systems, and (b) they aren't using wildcards, although a solution which acknowledged that a wildcard was in use would be useful too if it also provided a list of explicit domains.

share|improve this question
up vote 6 down vote accepted

I see two possible ways. First:

egrep '(ServerName|ServerAlias)' /path/to/httpd/conf/vhosts/* | uniq


dig @ PTR

Here is your server's external IP. Of course, this will do the trick if PTR records were maintained together with A records.

Or I missed something in your question?..

share|improve this answer
Your first suggestion works best; the second doesn't, I think possibly because PTR records weren't maintained. The grep pattern will need modifying for Nginx but that shouldn't be too hard. – pjmorse Jun 20 '11 at 16:28
I'm not an nginx expert, but I see "server_name" in nginx.conf – HUB Jun 20 '11 at 16:32
I think you're right, that string is all I'll need; Nginx doesn't distinguish between the ServerName and ServerAlias like Apache does, it just takes a list of names. – pjmorse Jun 20 '11 at 16:51
apache2ctl -S

Will print out virtual hosts for apache, but I don't know how to get this in nginx.

share|improve this answer
This is great, it lists all virtual hosts with ServerName, but doesn't include the ServerAliases. – pjmorse Jun 20 '11 at 16:27

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.