简体   繁体   English

是否可以在Windows上以编程方式控制Apache httpd?

[英]Is it possible to programatically control Apache httpd on Windows?

I would like to (preferably using Python) programmatically control Apache httpd on Windows. 我想(最好使用Python)以编程方式控制Windows上的Apache httpd。 That is, stop and start the service, and ideally add/remove/stop/start individual sites. 也就是说,停止并启动服务,理想情况下添加/删除/停止/启动单个站点。

I haven't found any existing libraries that do this. 我没有找到任何现有的库来执行此操作。 Is this a nonsensical endeavor (and if so, why)? 这是一个荒谬的努力(如果是这样,为什么)?

Or, is it possible to do this from the command line, and therefore just a matter of making the appropriate command line calls from within my program? 或者,是否可以从命令行执行此操作,因此只需从我的程序中进行适当的命令行调用?

Starting and stopping services has been implemented by many libraries, for example see here: 许多库已经实现了启动和停止服务,例如,请参见:

http://www.icodeguru.com/WebServer/Python-Programming-on-Win32/ch18.htm http://www.icodeguru.com/WebServer/Python-Programming-on-Win32/ch18.htm

Controlling individual websites (VirtualHosts) heavily depends on the configuration file layout. 控制各个网站(VirtualHosts)在很大程度上取决于配置文件布局。 For example, on Debian, a specific directory structure has been devised ( /etc/apache2/sites-available , /etc/apache2/sites-enabled ...) and specific scripts control file copies to the "enabled" directory ( a2ensite , a2dissite ). 例如,在Debian上,已经设计了一个特定的目录结构( /etc/apache2/sites-available/etc/apache2/sites-enabled ...),并且特定脚本将文件副本控制到“enabled”目录( a2ensitea2dissite )。

Such layout does not exist in the default Windows Apache distribution, so it is really up to you to replicate it and create the corresponding scripts or apis. 默认的Windows Apache发行版中不存在这样的布局,因此您需要复制它并创建相应的脚本或api。 This is the solution I recommend. 这是我推荐的解决方案。

Another approach would be to parse the apache configuration directly and comment-out specific sections as needed, but this is risky because any error in editing these files might keep apache from restarting altogether. 另一种方法是直接解析apache配置并根据需要注释掉特定部分,但这是有风险的,因为编辑这些文件时的任何错误都可能使apache无法完全重启。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM