使用 Apache HTTP 实例支持 Tomcat 的最简单方法

发布于 2024-07-16 18:35:00 字数 331 浏览 4 评论 0原文

我有一个 Tomcat 6 实例,由于多次 WAR 部署后的 PermGen 问题,经常需要重新启动。

在生产环境中,关闭网站显然是不好的做法,这只会给任何访问者带来连接失败的后果。 大局是设置一个或两个以上实例的故障转移 Tomcat 集群,但现在我想要一个简单的解决方案:

当 Tomcat 关闭时,所有请求都转发到运行 1 个简单“站点”的 Apache HTTP 服务器正在维护”类型页面。

我认为我需要一些小型、超快的代理来位于 Tomcat 前面,为其提供请求并监控其运行状况。 如果它挂掉,它只会将这些请求发送到 Apache HTTP。

有想法吗?

I have a single Tomcat 6 instance that frequently needs to be rebooted because of PermGen issues after multiple WAR deployments.

In a Production environment it's clearly bad practice to take down the site, leaving any visitors with nothing but a connection failure. The big picture is to set up a fail-over Tomcat cluster of one or two more instances, but for now I'd like a simple solution:

When Tomcat is down, all requests are forwarded to an Apache HTTP server running 1 simple "Site is under maintenance" type page.

I assume I need some small, super fast proxy to sit in front of Tomcat, feeding it requests and monitoring its health. If it dies, it simply sends those requests to Apache HTTP.

Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱,才寂寞 2024-07-23 18:35:00

通常,您可以在安装 tomcat 之前使用 Apache。 设置到您的 tomcat 的重定向代理规则。 如果这不起作用,apache 将发送“503 服务暂时不可用”,您可以将其配置为维护页面。

apache 应用程序文件看起来有点像这样

<VirtualHost *>
    ServerName example.com
    ServerAlias *.example.com
    ServerAdmin [email protected]

    RewriteEngine on
    RewriteRule ^/static/(.*) /some/path/for/static/files/static/$1 [L]
    RewriteRule ^(.*) http://127.0.0.1:8080$1 [P]

    ErrorLog /var/log/apache2/example/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/example/access.log combined
    ServerSignature On

    ErrorDocument 503 /static/site_down.html
</VirtualHost>

第一个重写规则将某个 URI ( /static/ ) 下面的所有文件更改为直接提供这些静态文件而无需代理的目录。 您也可以使用它来为您网站上的所有静态资源提供服务,这将在一定程度上弥补在 Tomcat 前面安装 apache 带来的一般(小)性能损失。

ErrorDocument 指令更改了对此静态路径中的文档 site_down.html 的正常 503 响应。

为此,您需要启用 mod_rewrite 和 mod_proxy/mod_proxy_http 以及
在 apache2 配置中启用代理

<Proxy *>
        Order Deny,Allow
        Deny from all
        Allow from all
</Proxy>

You could just generally use Apache in front of your tomcat install. Set up a redirect proxying rule to your tomcat. If that doesn't work, apache will send a "503 Service Temporarily Unavailable" which you could configure to be your maintenance page.

The apache application file would look somewhat like this

<VirtualHost *>
    ServerName example.com
    ServerAlias *.example.com
    ServerAdmin [email protected]

    RewriteEngine on
    RewriteRule ^/static/(.*) /some/path/for/static/files/static/$1 [L]
    RewriteRule ^(.*) http://127.0.0.1:8080$1 [P]

    ErrorLog /var/log/apache2/example/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/example/access.log combined
    ServerSignature On

    ErrorDocument 503 /static/site_down.html
</VirtualHost>

The first rewrite rule changes all files in below a certain URI ( /static/ ) to a directory from which those static files are served directly without proxying. You could use this to serve all static resources from your website, too, which would somewhat make up for the general (small) performance loss of having an apache in front of your tomcat.

The ErrorDocument directive changes the normal 503 response to the document site_down.html lying in this static path.

For this to work you need to enable mod_rewrite and mod_proxy/mod_proxy_http and
enable the proxy in your apache2 config

<Proxy *>
        Order Deny,Allow
        Deny from all
        Allow from all
</Proxy>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文