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.

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

2 Answers 2

up vote 6 down vote accepted

I see two possible ways. First:

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

Second:

dig @8.8.8.8 4.3.2.1.in-addr.arpa PTR

Here 1.2.3.4 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

 
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.