使用 Tomcat 的 CentOS Grails 应用程序的 Apache 重写规则

标签 apache tomcat grails url-rewriting centos

我在 CentOS 机器上使用 Apache 和 Tomcat,我想进行以下重写:

  1. 我想在收到请求时处理 abc.com 以重定向到 www.abc.com。
  2. 我想用 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 代理重写工作正常,我只需要在上面进行以下重写。

最佳答案

  1. apache redirect from non www to www
  2. 要使用 apache 而不是 tomcat 加载资源,您可以:
    • 使用 apache mod_cache 模块,因此您可以通过缓存资源(css、js、图像)来显着减少 tomcat 负载
    • 在您的网络应用程序中添加 servlet 过滤器以设置 http 缓存 header 以启用缓存

关于使用 Tomcat 的 CentOS Grails 应用程序的 Apache 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21660475/

相关文章:

grails - 客户端上的Grails表单验证

java - Apache ANT 独立 GUI,可轻松执行目标

apache - 如何使用 .htaccess 提供 gziped 字体? (没有 mod gzip 或 deflate)

java - 在 Java 中从 WebService 调用并行进程

tomcat - 我如何使用 grok 过滤器在 tomcat 日志中获取匹配的消息?

javascript - 如何将部分模板加载到grails中的div中

grails - 如何在 Grails 3.0.4 中配置插件的安装?

apache - Magento Admin/Front Split 服务器 Redis 错误

apache - 从 XAMPP 运行 apache 服务时出错

java - 如何在 MyEclipse 中调试 GWT 项目?