title: List all nginx sites from config
body: <p>While writing <code>php</code> script I need to list all nginx sites (vhosts) that's are set up on webserver, with ports and flag if the specific vhost is sll-enabled.</p>
  
  <p>I can do run and then parse <code>nginx -t</code> output. At first, I tried to use regexps, but the problem is, nginx can use different formated config, so this can be like this</p>
  
  <pre><code>server {
    server_name blah;
    listen 433 http2 ssl;
  ...
  }
  </code></pre>
  
  <p>or like this</p>
  
  <pre><code>server { server_name blah; listen 433 http2 ssl; root /siteroot1; listen 80; location / { ... } }
  </code></pre>
  
  <p>so it is a problem that pareser won't be fooled with some extra whitespaces or inline blocks.</p>
  
  <p>Another approach is to walk chars one by one and implement it with number of <code>strpos</code> checks. Again, it may be formating-sensitive.</p>
  
  <p>May there be any ready to use solution? Or maybe some another nginx command like args that make it list vhosts/ports only?</p>
  
  <p>Thank you!</p>