2

We have a Grails web application, running in tomcat7 behind Apache2. Everything works fine by using ProxyPass with the ajp protocol:

ProxyPass         / ajp://localhost:9013/
ProxyPassreverse  / ajp://localhost:9013/

where 9013 is our AJP port in tomcat's server.xml.

Now, our problem is this however. Our Grails application runs both HTTP and HTTPS. When going to a certain area in the application, Spring Security (Grails Spring Security Core plugin) redirects you from the address using HTTP to HTTPS, for example when hitting:

http://www.example.com/secure/path

Spring Security will redirect you to:

https://www.example.com/secure/path

But now, when it redirects there, the server hangs and finally Firefox gives the "Firefox has detected that the server is redirecting the request for this address in a way that will never complete." error.

Am I correct in assuming that some redirecting with the AJP proxy is going bad? Can anyone provide some more information regarding how this setup will work?


On looking further, we have found the following:

When hitting the application in tomcat directly (via IP and ports) everything works 100%. But as soon as we go through Apache, the Spring Security redirect does not work. you keep getting the following in the Apache logs:

staging.server.com:80 41.133.194.248 - - [05/Apr/2012:14:03:41 +0200] "GET /user/signup HTTP/1.1" 302 223 "http://staging.server.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"
staging.server.com:80 41.133.194.248 - - [05/Apr/2012:14:03:42 +0200] "GET /user/signup HTTP/1.1" 302 223 "http://staging.server.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"
staging.server.com:80 41.133.194.248 - - [05/Apr/2012:14:03:42 +0200] "GET /user/signup HTTP/1.1" 302 223 "http://staging.server.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"
staging.server.com:80 41.133.194.248 - - [05/Apr/2012:14:03:42 +0200] "GET /user/signup HTTP/1.1" 302 223 "http://staging.server.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"

...

rather than redirecting to https it seems apache magically makes it try http again. Thanks

4

5 に答える 5

2

解決方法はまだわかりませんが、何が問題なのかはわかります。

その本質的には、書き換えエントリ ポイントです。

したがって、これらの状況で行うべきことの一部が設定されています。

grails.plugins.springsecurity.secureChannel.useHeaderCheckChannelSecurity = true

これは、ヘッダーを設定することで本当に http/https を使用しているかどうかを調べます。デフォルトは次のとおりです。

RequestHeader set X-Forwarded-Proto "http"

これで、nginx で問題なく動作するようになりました。前面に apache がある場合の問題は、書き換えルールが apache サーバーをピックアップしないことです。彼らは単に自己を拾います。そのため、基本的に無限のリダイレクトにヒットするため、知っているのはあなたがいる9013サーバーだけです.

今は、独自のカスタム HttpsEntry を作成するだけだと思いますが、これを正しく機能させるための apache 設定がいくつかあると思います。

于 2012-05-06T00:49:24.293 に答える
1

Grails/Spring-Security には次のプロパティがあります。

grails {
   // redirect ports
   plugins {
      springsecurity {
         portMapper {
            httpPort = 80
            httpsPort = 443
         }
      }
   }
}

前述の httpd-config (ポート 80/443、Apache で終端された SSL) でそのために使用できます。server.urlプロパティを適切に設定することもできます。

于 2012-05-03T08:46:39.340 に答える
0

spring-security-coreがHTTPSに切り替えるときに使用するポートをどのように決定するかはわかりませんが、デフォルトのTomcat構成にはAJPコネクター用のredirectPort = "8443"があり、リダイレクトがApacheのHTTPSポートに到達するように443に変更する必要があります。 。

于 2012-04-05T12:36:11.280 に答える
0

ところで...これがあなたの答えです。

ポート マッパーの設定を行い、前に述べたようにチャネル セキュリティを使用します。

そのチャネル セキュリティは、いつ http/https に転送するかを知るために必要です。

ただし、リダイレクト内では、request.getServerPort() がそれらを見つけられるように、プロキシ設定を保持する必要があります。これを Apache httpd.conf に追加できます。

ProxyPreserveHost オン

于 2012-05-06T02:07:05.413 に答える
0

免責事項、私は Grails の専門家ではありません。

しかし、あなたが説明したことから、構成は次のようになります。

SSL は apache httpd にオフロードされます。したがって、Tomcat で構成する必要があるのは ajp コネクタのみであるか、テスト目的でのみ追加の http コネクタを使用する必要があります。http://httpd.apache.org/docs/2.0/ssl/ssl_howto.html および_

<VirtualHost _default_:80>

    RedirectPermanent /secure/path https://www.example.com/secure/path
    ProxyPass         / ajp://localhost:8009/
    ProxyPassreverse  / ajp://localhost:8009/
</VirtualHost>

<VirtualHost _default_:443>

    # SSL config
    ...
    ProxyPass         / ajp://localhost:8009/
    ProxyPassreverse  / ajp://localhost:8009/
</VirtualHost>

動作するはずです。

もう 1 つの利点は、SSL が apache httpd にオフロードされると、パフォーマンスが向上する可能性があることです。

さらに、すべてに SSL を強制しない理由は次のとおりです。

<VirtualHost _default_:80>
RedirectPermanent / https://www.example.com/
</VirtualHost>

<VirtualHost _default_:443>

# SSL config
    ...

ProxyPass         / ajp://localhost:8009/
ProxyPassreverse  / ajp://localhost:8009/
</VirtualHost>

無限ループが発生する理由については、Spring Security の sendRedirect に関連している可能性があります。完全な apache VirtualHost と tomcat ajp コネクタの構成を投稿していただければ、より多くの手がかりが得られる可能性があります。

于 2012-04-05T15:09:06.210 に答える