我正试图在ec2上设置一个反向代理,以便通过使用nginx的自定义域名提供对我的appengine应用程序的安全访问。它似乎工作得很好,除了页面需要用户服务的时候。它重定向到Google帐户登录,然后转到appspot域,而不是我的自定义域。我知道appengine在测试中有ssl,但我想要一个我现在可以使用的解决方案。有没有可能克服这个问题,或者我需要创建我自己的用户?
以下是我的配置:
server {
listen 443;
server_name <custom-domain>;
keepalive_timeout 70;
ssl on;
ssl_certificate /etc/nginx/cert/server.crt;
ssl_certificate_key /etc/nginx/cert/server.key;
ssl_session_timeout 30m;
location / {
proxy_redirect off;
proxy_pass https://<appid>.appspot.com;
proxy_set_header Host <appid>.appspot.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_intercept_errors off;
}
}我的域名有一个指向ec2的CNAME。
===
我找到了一种解决方法。仍然希望有一个更简单的,并希望得到反馈。
1) Client hits https: //mydomain.com/blah which goes through EC2 proxy https://appid.appspot.com/blah
2) The client is redirected to the google login page, with continue set as /aa?continue=/blah
3) Client logs into Google Accounts and is then redirected to https: //appid.appspot.com/aa?continue=/blah
4) Client hits https: //appid.appspot.com/aa which serves a redirect to https://mydomain.com/sc?c=ACSID&continue=/blah where ACSID is the Google account session cookie read by the handler for /aa.
5) Client hits https: //mydomain.com/sc?c=ACSID&continue=/blah which sets the ACSID session cookie for the domain mydomain.com and redirects to https: //mydomain.com/blah based on a continue parameter in aa passed to sc以下是我的web.xml
/ is publicly accessible
/aa is publicly accessible
/sc is publicly accessible
/* is restricted to logged in users以下是处理程序中的限制(使用一些棘手的url转义):
/ --> if not logged in, redirect to login page continue=/aa
/aa --> if not logged in, redirect to login page continue=/aa
/sc --> if not logged in, redirect to login page continue=/aa
/* --> if not logged in, redirect to login page continue=/aa?continue=*此后,即使通过使用SSL的代理服务,用户服务似乎也可以正常工作。ACSID cookie现在位于mydomain.com上,并通过代理发送到appengine。
appspot域名仍然会显示给精通技术的用户,但这不是我主要关心的问题。我的目标是通过https提供服务,并将我的自定义域名保留在url栏中,并且使用我的自定义域名在不使用SSL的情况下更安全地提供用户数据。由于整个事务都是通过https完成的,因此我认为这不会比使用不带SSL的mydomain.com更多地公开会话cookie。即使没有这个方案,任何其他的跨站点攻击也可以工作。
我仍然不确定为什么mydomain.com/_ah/conflogin?state=blah会失败,需要解决这个问题。
发布于 2014-02-18 00:22:18
您的变通方法为我解决了这个问题--谢谢!
这是我想出来的代码,适用于任何其他遇到同样情况的人。这是一些特定于站点的东西,因此可能需要进行一些调整才能正常工作。cookie是SACSID,因为我使用的是https;我认为它应该是http的ACSID。
class CompleteLoginHandler(BaseHandler):
def get(self):
redirect_to=self.request.get('next', '/')
if not redirect_to.startswith('/'): # don't allow redirects to another domain
redirect_to = '/'
session_id = self.request.get('SACSID', None)
if session_id:
self.response.set_cookie('SACSID', session_id)
return self.redirect(redirect_to)
class PostLoginRedirectHandler(BaseHandler):
def get(self):
domain = self.request.headers.get('X-Forwarded-Host', None)
if domain is None:
# we are on the bare url; need to transfer the user -- and cookie
sacsid = self.request.cookies.get('SACSID')
next_url = config['domain'] + self.uri_for('complete_login', next=self.uri_for(route_name), SACSID=sacsid)
return self.redirect(next_url)
else:
return self.redirect('/')这里,PostLoginRedirectHandler处理的是步骤(4),而CompleteLoginHandler处理的是tarun2000描述的步骤(5)
https://stackoverflow.com/questions/9780557
复制相似问题