我在 CentOS 机器上使用 Apache 和 Tomcat,我想进行以下重写:
- 我想在收到请求时处理 abc.com 以重定向到 www.abc.com。
- 我想用 Apache 而不是 Tomcat 加载我的资源
这是我的配置文件。它位于/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 redirect from non www to www
- 要使用 apache 而不是 tomcat 加载资源,您可以:
- 使用 apache mod_cache 模块,因此您可以通过缓存资源(css、js、图像)来显着减少 tomcat 负载
- 在您的网络应用程序中添加 servlet 过滤器以设置 http 缓存 header 以启用缓存
关于使用 Tomcat 的 CentOS Grails 应用程序的 Apache 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21660475/