我有一个类似的设置,只是 Tomcat 而不是 Glassfish,而 maven 来构建一切。这是它的工作原理。Apache httpd 和 Tomcat 使用 mod_jk 连接。Apache 将所有请求转发到 Tomcat,除了 GWT 模块目录(我们称之为 gwt_module),它包含所有 GWT 编译的东西 - 由 Apache 提供服务并配置为缓存。其余的 - 基本上是 servlet,被转发到 Tomcat(RPC、RequestFactory、其他 servlet)。MongoDB 作为数据库服务器。
这是相关的 httpd.conf 部分:
JkMount /* webbalancer
JkUnMount /gwt_module/* webbalancer
Alias /gwt_module "/srv/web/app_servers/tomcat-1/webapps/ROOT/gwt_module/"
<Directory "/srv/web/app_servers/tomcat-1/webapps/ROOT/gwt_module/">
Order deny,allow
allow from all
Options -Indexes
<FilesMatch "\.cache\.*">
Header set Cache-control max-age=31536000
# Header unset ETag
# FileETag None
</FilesMatch>
# turning off ETags, to force browsers to rely only on Cache-Control and Expires headers.
# for some reason, FF wasn't using the cache for JS files if ETags are on.
Header unset ETag
FileETag None
</Directory>
# Tell clients to keep images in the cache
ExpiresActive On
ExpiresByType image/x-icon A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
#ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType application/xhtml+xml A2592000
# Compress output for text
AddOutputFilterByType DEFLATE text/html text/xml text/css application/x-javascript text/javascript application/javascript
注意:我不确定使用 apache 提供静态文件是否比只使用 tomcat 提供所有内容要快,我主要使用 apache 进行负载平衡。