带SSL的Django Runserver

时间:2012-08-24 00:31:59

标签: django ssl stunnel

我一直在尝试遵循使用django runserver和ssl到stunnel的说明:

How can I test https connections with Django as easily as I can non-https connections using 'runserver'?

但是我遇到了一些麻烦。我有stunnel和两个运行服务器,每个运行在虚拟环境中。每个人似乎都在为自己工作。

stunnel.pem看起来像这样:

-----BEGIN RSA PRIVATE KEY-----
(random)
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
(random)
-----END CERTIFICATE-----

dev_https看起来像这样:

pid=

cert = stunnel/stunnel.pem
sslVersion = SSLv3
foreground = yes
output = stunnel.log

[https]
accept=8443
connect=8001
TIMEOUTclose=1

当我尝试访问

https://127.0.0.1:8443/ 

这是发生的事情:

Stunnel,执行时:

stunnel4 dev_https

显示了这一点:

2012.08.23 20:20:58 LOG5[3818:140280034400000]: Service https accepted connection from 127.0.0.1:44302
2012.08.23 20:20:58 LOG5[3818:140280034400000]: connect_blocking: connected 127.0.0.1:8001
2012.08.23 20:20:58 LOG5[3818:140280034400000]: Service https connected remote server from 127.0.0.1:34622
2012.08.23 20:20:58 LOG5[3818:140280034400000]: Connection closed: 187 bytes sent to SSL, 422 bytes sent to socket

服务器执行:

python2.7 manage.py runserver

所示:

(nothing)

服务器执行:

HTTPS=1 python2.7 managpy runserver 8001

所示:

[23/Aug/2012 19:20:58] "GET / HTTP/1.1" 301 0

最后,浏览器中的网页请求显示标准的chrome错误:

This webpage is not available
The server at 127.0.0.1 can't be found, because the DNS lookup failed.

我很欣赏有关我可以改变什么或者我做错了什么的建议。谢谢你的帮助!

更新 我现在收到此错误消息:

----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52878)  
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 582, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 139, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 638, in __init__
self.handle()
   File "/usr/lib/python2.7/wsgiref/simple_server.py", line 116, in handle
self.raw_requestline = self.rfile.readline()
  File "/usr/lib/python2.7/socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 104] Connection reset by peer
 ----------------------------------------

0 个答案:

没有答案