php - 从 php 脚本显示虚拟主机?

标签 php apache2 vhosts

我希望能够构建一个脚本来显示在我的 Apache (Ubuntu) 开发机器下运行的所有虚拟主机。

迄今为止,我还没有找到任何示例或任何接近我想要的东西,这只是:

“显示 native 上运行的所有虚拟主机”。 (服务器名称、别名等)。

我想我也许能够读取/etc/apache2/sites-available 文件夹,其中包含虚拟主机的所有conf文件,但在走这条路之前,我想我应该先在这里问一下。

最佳答案

您可以使用apachectl(或apache2ctl)命令向httpd Apache 服务器发出信号以转储虚拟主机信息:

 apache2ctl -St

以下是使用 apachectl 的链接发送信号和 httpd flags .

这是我的 Apache/Ubuntu 系统上的样子(我是一名拥有大量虚拟主机的 Web 开发人员):

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost adaleco (/etc/apache2/sites-enabled/adaleco:1)
         port 80 namevhost amcham (/etc/apache2/sites-enabled/amcham:1)
         port 80 namevhost cake (/etc/apache2/sites-enabled/cake:1)
         port 80 namevhost cakeplate (/etc/apache2/sites-enabled/cakeplate:1)
         port 80 namevhost coord (/etc/apache2/sites-enabled/coord:1)
         port 80 namevhost dru1 (/etc/apache2/sites-enabled/dru1:1)
         port 80 namevhost flaming (/etc/apache2/sites-enabled/flaming:1)
         port 80 namevhost flaming6 (/etc/apache2/sites-enabled/flaming6:1)
         port 80 namevhost food (/etc/apache2/sites-enabled/food:1)
         port 80 namevhost fun (/etc/apache2/sites-enabled/fun:1)
         port 80 namevhost marc (/etc/apache2/sites-enabled/marc:1)
         port 80 namevhost sugar (/etc/apache2/sites-enabled/sugar:1)
         port 80 namevhost vol (/etc/apache2/sites-enabled/vol:1)
         port 80 namevhost xmas (/etc/apache2/sites-enabled/xmas:1)
Syntax OK

关于php - 从 php 脚本显示虚拟主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15646835/

相关文章:

php - 命令行和 apache 中的不同版本的 php

php - Apache,如何处理未知的 php 文件,如标准 URL?

php - 在 Nginx 中显示 PHP 错误而不是 502 Bad Gateway

php - 如何在 Yii CHtml::link 中包含 javascript 操作?

apache2 - 为什么 Apache 不将我的 IP 地址重定向到服务器上的所需位置?

linux - 从远程设备浏览本地主机上的网站

PHP cURL 看不到/etc/hosts 文件

php - en_CA 语言环境中 sprintf 中的逗号作为小数点分隔符

php - 使用 ldap 列出用户的组

升级到 OSX El Capitan 后,Wordpress 永久链接无法正常工作