3

我有一个在 tomcat 上运行的 grails 应用程序,我正在使用 mod_proxy 将 http 服务器与它连接。我的目标是保护登录过程。

我强制使用 https 的 VirtualHost 配置是:

ProxyPass /myapp/ http://127.0.0.1:8080/myapp
ProxyPassReverse /myapp/ http://127.0.0.1:8080/myapp

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(myapp/login) https://%{HTTP_HOST}:443/$1 [NC,R=301,L]

当我去https://mydomain.com/myapp/adm - 这需要身份验证 - 它重定向到http://mydomain.com/myapp/login/auth;jsessionid=yyyyyy,没有安全所以重写不起作用(如果我用 https 手动替换 http,它工作正常)。

有什么提示吗?

4

3 回答 3

1

你打错了,你想要这个:

RewriteRule ^/myapp/login https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

您当前的 RewriteRule 永远无法匹配

我也怀疑有这个意义

RewriteCond %{THE_REQUEST} ^[A-Z]+\s/myapp/login [NC]

这只会复制您在 RewriteRule 中想要的 ^/myapp/login。因此,尽管它起作用,但它没有任何作用。

于 2013-01-31T09:57:38.357 回答
1

当我去https://mydomain.com/myapp/adm - 这需要身份验证 - 它重定向到 http://mydomain.com/myapp/login/auth;jsessionid=yyyyyy

看起来 Spring 安全执行重定向到 /login/auth。Burt Beckwith在这里提到 spring security 不需要 grails.serverURL。它应该使用 request.getServerName() 基本上 grails.serverURL 已用于 createLink方法

我会建议:

  1. 尝试在 grails.serverURL 中使用 https 用于生产环境
  2. 设置应用程序上下文(如果第 1 项)没有帮助):

    grails.app.context="/myapp"

更新

只是为了隔离和更好地了解问题出在哪里:

您能否使用 https 运行 grails(在开发环境中)并检查一切是否正常:

grails run-app -https
于 2013-01-28T17:46:37.387 回答
1

在同时允许 http 和 https 的设置中,将单独的 Connector 元素添加到 tomcat 的 conf/server.xml 文件中:

<Connector port="8081" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           redirectPort="8443"  URIEncoding="UTF-8"
           scheme="https" secure="true" proxyName="somehostname.domain" proxyPort="443" />

如果只允许 https,您可以将 scheme、secure、proxyName 和 proxyPort 属性添加到现有的 Connector 元素。

在 apache 配置中,使用额外属性将 *:443 虚拟主机代理到连接器。普通的 http *:80 可以连接到原始的连接器。

更多信息: http: //tomcat.apache.org/tomcat-7.0-doc/config/http.html#Proxy_Support http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html

于 2013-01-31T18:27:56.167 回答