Apache 模块已安装,但在 Ubuntu 中似乎未加载
我对 Linux 还很陌生。昨天设置了一个VPS,安装了Apache2、PHP5和MySQL。
当我执行 apache2 -l 时,我得到这个:
Compiled in modules: core.c mod_log_config.c mod_logio.c prefork.c http_core.c mod_so.c
当我执行 sudo a2enmod rewrite 时,我得到这个:
Module rewrite already enabled
并且 rewrite.load 位于
中/etc/apache2/mods-enabled
。
谁能告诉我出了什么问题吗?
I am pretty new to Linux. Got a VPS set up yesterday, installed Apache2, PHP5 and MySQL.
When I do apache2 -l
I get this:
Compiled in modules: core.c mod_log_config.c mod_logio.c prefork.c http_core.c mod_so.c
When I do sudo a2enmod rewrite
I get this:
Module rewrite already enabled
And rewrite.load
is in /etc/apache2/mods-enabled
.
Can anyone tell what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这确实属于 ServerFault,但由于它最终可能会被迁移,所以我会继续说编译到 Apache 的模块和动态加载的模块之间存在差异。
Apache 能够以两种不同的方式加载模块。 “更简单”的方法是将模块静态编译到服务器中。这意味着可执行文件 apache2 确实包含了该模块的代码。这种方法的优点是模块始终可用,Apache 无需执行任何特殊操作即可访问其代码,但另一方面,如果您想添加、删除或更新静态编译的模块,你必须重新编译所有的 Apache。另外,静态编译的模块越多,可执行文件就越大。由于这些原因,该列表通常只包含一些最基本的模块,基本上是 Apache 运行所需的最低限度。这几个模块是您运行 apache2 -l 时看到的列表中显示的模块。
Apache 使用的所有其他模块(包括 mod_rewrite)都是动态加载的。也就是说,它们的代码存储为单独的文件,Apache 在启动后找到并读取这些文件。这消除了静态编译方法的缺点:由于模块存储在单独的文件中,如果要添加/删除/更改模块,只需重新启动服务器,而不需要重新编译。您可以通过在 Apache 配置文件中放入
LoadModule
指令来告诉 Apache 要加载哪些模块。这基本上就是a2enmod
的作用:它将LoadModule
指令添加到配置文件中。 (实际上,它将存根配置文件符号链接到主配置来源的目录中)如果您想查看已加载模块的完整列表,包括动态加载的模块,您可以运行
您必须确保运行 Apache不过,与 Ubuntu 的 init 脚本相同。系统在启动 Apache 之前读取配置文件或其他内容是很常见的,如果您不这样做,则可能会更改加载的模块集。
This really belongs on ServerFault, but since it'll probably get migrated eventually I'll go ahead and say that there's a difference between modules that are compiled into Apache and modules that are dynamically loaded.
Apache is able to load modules in two different ways. The "simpler" way is for the module to be statically compiled into the server. This means that the executable file
apache2
literally includes the module's code. The advantage of this approach is that the module is always available and Apache doesn't have to do anything special to get access to its code, but on the other hand, if you want to add, remove, or update a statically compiled module, you have to recompile all of Apache. Plus, the more modules that are statically compiled, the bigger the executable file becomes. For these reasons, it's normal for that list to only include a few of the most essential modules, basically the minimum necessary for Apache to run. Those few modules are the ones that appear in the list you see when you runapache2 -l
.All the other modules that Apache uses, including
mod_rewrite
, are dynamically loaded. That is, their code is stored as separate files, which Apache locates and reads in after it's started up. This negates the disadvantages of the static compilation approach: since the modules are stored in separate files, if you want to add/remove/change one, you only need to restart the server, not recompile it. You can tell Apache which modules to load by puttingLoadModule
directives in your Apache configuration file. This is basically whata2enmod
does: it adds aLoadModule
directive to the configuration file. (Actually it symlinks a stub configuration file into a directory that is sourced by the main configuration)If you want to see a complete list of loaded modules, including the dynamically loaded ones, you can run
You'll have to make sure to run Apache in the same way as Ubuntu's init script, though. It's common for the system to read in a configuration file or something before it starts Apache up, and if you don't do the same, it might change the set of modules that gets loaded.