我在 CentOS 机器上使用 Apache 和 Tomcat,我想进行以下重写:
- 我想处理 abc.com,以便在发出请求时重定向到 www.abc.com。
- 我想用Apache而不是Tomcat加载我的资源
这是我的 conf 文件。它位于/etc/httpd/conf.d/tomcat.conf
#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL. To disable the Welcome page, comment
# out all the lines below.
#
RewriteEngine on
RewriteRule ^/images/(.*) /images/$1
RewriteRule ^/css/(.*) /css/$1
RewriteRule ^/js/(.*) /js/$1
RewriteCond %{HTTP_HOST} ^abc.com
RewriteRule ^(.*)$ http://www.abc.com$1 [R=301,L]
NameVirtualHost *:80
<VirtualHost *:80>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / ajp://127.0.0.1:8009/
ProxyPassReverse / ajp://127.0.0.1:8009/
ProxyPassReverseCookiePath / /
</VirtualHost>
我的 AJP 代理重写正在工作,我只需要在上面进行以下重写。
- Apache 从非 www 重定向到 www
- 要使用 apache 而不是 tomcat 加载资源,您可以:
- 使用 Apache mod_cache 模块,因此您可以通过缓存资源(CSS、JS、图像)来显着减少 Tomcat 负载
- 在 Web 应用程序中添加 Servlet 过滤器以设置 HTTP 缓存标头以启用缓存