From Apache to Nginx

我感觉配置 nginx 渐入佳境了。配置 nginx 时应该用不同 apache 的思维,最主要的不同点是:

apache 是 fallback 式配置,比如有两个 <directory> block,分别是 mydirectory 和 mydirectory/subdir。mydirectory/subdir 可以重写 mydirectory 的 directives,但 mydirectory/subdir 没有提到的 directives 就沿袭 mydirectory 的 directives。

nginx 是 parallel 式配置,location 只能按优先规则取其一。

另外,我觉得有人批评 apache 层层检测 .htaccess 造成效率低下的一个原因。我感觉这种说法并不妥,很多 apache 发行版默认 allowoverride none,用户只要根据需要在确实需要启用 .htaccess 的那一层启用 allowoverride,这并不造成效率损失,反而带来配置的灵活性。当然,nginx 不需要这种灵活性,因为它不是面向 share hosting 的产品。

除了内存占用大是 apache 的硬伤,其他 nginx 的优势并不明显,apache 同样可以优化配置达到相应的效果,尽管很多配置不是 apache 的默认配置。(这只是我的总体感觉,我并没有深入去比较,欢迎探讨。)

Leave a comment

Your email address will not be published. Required fields are marked *