大网数据广告活动
服务器运维问答

Apache2 mod rewrite extremely slow, on one server only

· 52CE 我爱测

I have a site on my local ubuntu dev box with some mod rewrite rules, which we are attempting to use to force google and other bots to index the correct page, rather than our ajax snippets as they have been doing. Although the ru…

问题原文

原帖链接 · sgc · CC BY-SA 4.0

I have a site on my local ubuntu dev box with some mod rewrite rules, which we are attempting to use to force google and other bots to index the correct page, rather than our ajax snippets as they have been doing. Although the rules are a bit longer that the snippet below, by disabling everything a section at a time, I find that even the most basic rewrite fails on the production server, but works fine on dev, even handling load testing with 14k requests via cUrl, no problem. We are using rewrite because proxypass doesn't work inside an <if>, and can't work based on %{QUERY_STRING}.

ProxyPass we were using before:

ProxyPreserveHost on
ProxyPass ajp://127.0.0.1:8009/other/view retry=0
ProxyPassReverse ajp://127.0.0.1:8009/request/view

The simple rewrite that causes 0.3 second mod_proxy request on dev to take upwards of 30 seconds on production:

RewriteRule ^(.*)(/request/view) ajp://localhost:8009/other/view [P]

Both servers are ubuntu and use the same version of apache:

Server version: Apache/2.4.52 (Ubuntu)
Server built:   2022-06-14T12:30:21

Both use LogLevel warn

I have used diff to verify that both files contain identical rewrite rules. I have checked that they both load the same mods (the dev box does load one mod that is not on prod, fcgid, but we are not using cgi anyways). The only thing of note we can think of, is that dev is http, and prod is https. This problem is immediate on loading the above rewrite condition and rule, and evaporates reverting to the ProxyPass directive - it is not tomcat9 based.

I need help on the next steps in troubleshooting, thanks.

已采纳解答

原帖链接 · sgc · CC BY-SA 4.0

I never found out why this happened, but I did determine it was due to an error in the [P] flag (mod_rewrite forward to mod_proxy) processing on the server. The following work-around is compatible with our larger rewrite chain:

<location /request/view>
   ...
   # passthrough to reprocess url matching
   RewriteRule "/request/view$" "$0/proxy" [PT]
</Location>
#new location that just uses ProxyPass
<Location /request/view/proxy>
   ProxyPreserveHost on
   ProxyPass ajp://127.0.0.1:8009/other/view retry=0
   ProxyPassReverse ajp://127.0.0.1:8009/request/view
</Location>

I suspect that the way mod_rewrite hands off to mod_proxy on our server, is very inefficient when using ssl.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-08-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。