apache

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Apache HTTP Server (httpd)

Apache HTTP Server (httpd)

Apache is a robust, modular web server. While Nginx leads in raw performance, Apache leads in flexibility via
.htaccess
. v2.4 remains the stable standard in 2025.
Apache 是一款健壮的模块化网页服务器。虽然 Nginx 在原始性能上更具优势,但 Apache 通过
.htaccess
实现了更强的灵活性。截至2025年,v2.4仍是稳定的标准版本。

When to Use

适用场景

  • Shared Hosting:
    .htaccess
    allows per-directory config without restarting the server.
  • Dynamic Modules: Loading modules without recompiling.
  • Legacy Apps: Many PHP/Perl apps are pre-tuned for Apache.
  • 共享主机托管
    .htaccess
    允许无需重启服务器即可进行目录级配置。
  • 动态模块:无需重新编译即可加载模块。
  • 遗留应用:许多PHP/Perl应用已针对Apache预先优化。

Core Concepts

核心概念

MPM (Multi-Processing Modules)

MPM(多处理模块)

  • prefork
    : Compatible with non-thread-safe libraries (old PHP).
  • event
    : Modern, async I/O. Best for high concurrency.
  • prefork
    :兼容非线程安全库(如旧版PHP)。
  • event
    :现代异步I/O模块,最适合高并发场景。

VirtualHosts

虚拟主机(VirtualHosts)

Serving multiple domains from one IP.
通过单个IP地址托管多个域名。

.htaccess

.htaccess

Files in the web root that override config. Convenient but slows performance.
位于网站根目录的配置文件,可覆盖全局配置。使用便捷但会影响性能。

Best Practices (2025)

2025年最佳实践

Do:
  • Use
    event
    MPM
    : It rivals Nginx in connection handling.
  • Disable
    .htaccess
    : If you have root access, put config in
    httpd.conf
    Directory
    blocks for performance.
  • Use HTTP/2: Enable
    mod_http2
    .
Don't:
  • Don't enable unnecessary modules: Reduce attack surface.
建议
  • 使用
    event
    MPM
    :其连接处理能力可与Nginx媲美。
  • 禁用
    .htaccess
    :若拥有服务器根权限,将配置放入
    httpd.conf
    Directory
    块中以提升性能。
  • 启用HTTP/2:开启
    mod_http2
    模块。
不建议
  • 不要启用不必要的模块:减少攻击面。

References

参考资料