【问题标题】:Display virtual hosts from a php script?从 php 脚本显示虚拟主机?
【发布时间】:2013-03-16 19:47:46
【问题描述】:

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

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

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

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

【问题讨论】:

  • 我认为阅读conf文件是唯一的方法。
  • vhost 文件可以在任何地方或主 conf 文件的一部分。如果 apache 没有用于获取定义的虚拟主机的 api,我看不到任何简单的方法来解决这个问题。除非保证您有特定的安装配置文件。

标签: php apache2 vhosts


【解决方案1】:

您可以使用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

【讨论】:

  • 嘿,Scott,这对你有用还是你有其他想法(不确定是否通过脚本你想要一个原生 PHP API)?
  • 我想要的是一个 php 脚本,当在我的本地机器上激活时,它会简单地吐出上面显示的内容,所以我编写了一个快速的 php 脚本来读取启用站点的目录,然后吐出每个文件的内容。不过,我想我会修改它以使用 apache2ctl 命令。谢谢,约翰。完成后我会发布我的脚本。
  • windows httpd.exe的命令参数是否存在?
猜你喜欢
  • 2015-01-12
  • 2013-08-24
  • 1970-01-01
  • 1970-01-01
  • 2012-04-26
  • 2017-12-09
  • 2022-12-09
  • 2017-10-24
  • 2018-06-26
相关资源
最近更新 更多