谷歌应用程序引擎 - 如何运行服务器作为HTTPS的Python?

时间:2013-08-20 21:22:47

标签: google-app-engine web https

在运行Google App Engine时,可以以http身份运行,但如何将其作为https运行?

$ python2.7 /var/tmp/google_appengine/dev_appserver.py --host 0.0.0.0 /var/tmp/app
INFO     2013-08-20 21:21:21,093 dispatcher.py:164] Starting module "default" running at: http://0.0.0.0:8080
INFO     2013-08-20 21:21:21,099 admin_server.py:117] Starting admin server at: http://localhost:8000

编辑:

第1步:

I purchased a.crt and a.key from a service provider such as heart internet from UK.

步骤2:我将a.crt和a.key文件放在内容

sun@sun-M14xR2:/var/tmp/private$ ls
a.crt  a.key
sun@sun-M14xR2:/var/tmp/private$ cat a.key a.crt > server.pem
sun@sun-M14xR2:/var/tmp/private$ ls
a.crt  a.key server.pem
sun@sun-M14xR2:/var/tmp/private$ openssl gendh >> server.pem
Generating DH parameters, 512 bit long safe prime, generator 2
This is going to take a long time
......................++*++*++*++*++*++*
sun@sun-M14xR2:/var/tmp/private$ stunnel -d 8443 -p server.pem -r localhost:8000 -f -P ''
2013.08.21 09:03:10 LOG5[5368:139785875400448]: stunnel 4.53 on x86_64-pc-linux-gnu platform
2013.08.21 09:03:10 LOG5[5368:139785875400448]: Compiled with OpenSSL 1.0.1 14 Mar 2012
2013.08.21 09:03:10 LOG5[5368:139785875400448]: Running  with OpenSSL 1.0.1c 10 May 2012
2013.08.21 09:03:10 LOG5[5368:139785875400448]: Update OpenSSL shared libraries or rebuild stunnel
2013.08.21 09:03:10 LOG5[5368:139785875400448]: Threading:PTHREAD SSL:+ENGINE+OCSP Auth:LIBWRAP Sockets:POLL+IPv6
2013.08.21 09:03:10 LOG5[5368:139785875400448]: Reading configuration from descriptor 3
2013.08.21 09:03:10 LOG4[5368:139785875400448]: Insecure file permissions on server.pem
2013.08.21 09:03:10 LOG5[5368:139785875400448]: Configuration successful

1 个答案:

答案 0 :(得分:6)

我相信app engine会在部署时自动运行为Https。在本地,无法以https身份运行。

然而,您可以运行stunnel来模拟它。

stunnel -d 8443 -p /path/to/ssl.pem -r localhost:8880 -f -P '' &

(你必须创建ssl.pem文件)(还假设8880是运行服务器的端口)

基本上,这将为您的应用提供类似于ssl的代理。您将在浏览器中收到警告,但这对于本地测试来说已经足够了。

编辑:

不确定那里发生了什么。我忘了提到你需要使用   https://本地主机:8443 从浏览器连接时。