如何运行django sslserver(https),以便网络中的远程系统也可以访问?

时间:2015-10-07 07:32:27

标签: python django ubuntu ssl https

我正在尝试使用https运行我的服务器,因此我安装了django-sslserver,并运行如下。

python manage.py runsslserver --certificate /etc/ssl/certs/server.crt --key /etc/ssl/private/server.key 0.0.0.0:8000

使用上述命令成功运行。我可以通过localhost:8000127.0.0.1:8000进行访问,但无法通过192.168.2.13:8000访问此处192.168.2.13是我的IP地址。

为什么我无法通过我的IP地址访问?

即使启动服务器而不是8000端口,它也默认为8000。在下面的示例中,我使用了8014,但它将8000视为默认值。

root@nagapavan-HP-ProBook-440-G2:/home/nagapavan/Downloads/celestial_NAS# python manage.py runsslserver --certificate /etc/ssl/certs/server.c --key /etc/ssl/private/server.key 127.0.0.1:8014
Validating models...
System check identified some issues:

WARNINGS:
NAS.UserProfile.user: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
    HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
System check identified 1 issue (0 silenced).
October 06, 2015 - 13:21:40
Django version 1.8.4, using settings 'celestial_NAS.settings'
Starting development server at 127.0.0.1:8000/
Using SSL certificate: /etc/ssl/certs/server.crt
Using SSL key: /etc/ssl/private/server.key
Quit the server with CONTROL-C

为什么默认使用端口号8000?

我发现了另外一个启动服务器的命令,如下所示。我可以给出IP地址和端口号。它按预期工作。但我可以使用IP地址访问但无法通过localhost:9000127.0.0.1:9000访问,即使我正在访问本地系统本身的服务器。

上述声明可能是什么原因?

即使我能够通过https://192.168.2.13:9000的IP地址访问,我也无法从位于同一网络的远程系统访问服务器(甚至可以相互ping通)

为什么我无法从同一网络中的远程系统访问服务器,我们是否需要更改配置文件?

python manage.py runsslserver --certificate /etc/ssl/certs/server.c --key /etc/ssl/private/server.key --addrport 192.168.2.13:9000

注意:上面使用 https

访问的所有URI

添加启动sslserver时遇到的错误,如下所示:

这是上述问题的原因吗?

----------------------------------------
----------------------------------------
Exception happened during processing of request from ('192.168.1.166', 56694)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 102, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
    self.handle()
  File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 167, in handle
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File "/usr/lib/python2.7/ssl.py", line 341, in recv
    return self.read(buflen)
  File "/usr/lib/python2.7/ssl.py", line 260, in read
    return self._sslobj.read(len)
SSLError: [Errno 1] _ssl.c:1429: error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca
----------------------------------------
----------------------------------------

1 个答案:

答案 0 :(得分:-1)

请使用它而不是0.0.0.0,请尝试使用您的网络IP,并允许在主机上添加网络IP