【发布时间】:2012-12-22 09:24:58
【问题描述】:
给定路径 X 或 apache vhosts 配置文件的副本,我将如何使用 PHP 解析该文件?
例如给定一个包含 Apache vhosts 配置内容的字符串的变量,我将如何获取托管域/子域别名的列表?
例如,给定:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin contact@tomjn.com
DocumentRoot "/srv/www/localhost/
ServerName 127.0.0.1
ServerAlias localhost
CustomLog "/srv/www/logs/localhost-access_log.log" combined
ErrorLog "/srv/www/logs/localhost-error_log.log"
<Directory "/srv/www/localhost">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin contact@tomjn.com
DocumentRoot "/srv/www/2.7.localhost.com/
ServerName 2.7.localhost.com
ServerAlias 2.7.localhost.com
CustomLog "/srv/www/logs/2.7.localhost.com-access_log.log" combined
ErrorLog "/srv/www/logs/2.7.localhost.com-error_log.log"
<Directory "/srv/www/2.7.localhost.com">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我如何得到这个输出:
- 本地主机
- 2.7.localhost.com
这是用 Python 编写的非常接近的东西:
【问题讨论】:
-
通过快速搜索,我没有看到任何已经执行此操作的 php 库...您可能只需要自己解析它。快速搜索确实产生了一个 python 库poldylicious.de/system/files/apacheconfig.py.txt
-
嗯,这被标记为重复但我找不到这样的重复?
-
嗯,这不是重复的,它也没有回答我的问题。那家伙想找到错误日志,我不想。答案也没有给我我需要的东西