1

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.

2 Answers 2

6

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?..

3
  • 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, 2011 at 16:28
  • I'm not an nginx expert, but I see "server_name" in nginx.conf
    – HUB
    Jun 20, 2011 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, 2011 at 16:51
2
apache2ctl -S

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

1
  • This is great, it lists all virtual hosts with ServerName, but doesn't include the ServerAliases.
    – pjmorse
    Jun 20, 2011 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .