1

我在具有公共 IP 的服务器上启动了一个新的 Django APP,然后使用以下命令运行它:

python manage.py runserver publicip:port

然后我发现当我使用它访问它时http://publicip:port工作正常。但是当我使用域名(解析为这个ip)访问它时,它失败了,并给出了错误:(https://dpaste.de/FIrk

0 errors found
October 10, 2013 - 10:31:13
Django version 1.5.1, using settings 'testsite.settings'
Development server is running at http://*.*.*.*:8709/
Quit the server with CONTROL-C.

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 86, in run
    self.finish_response()
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response
    self.write(data)
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 210, in write
    self.send_headers()
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 268, in send_headers
    self.send_preamble()
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 189, in send_preamble
    self._write('HTTP/%s %s\r\n' % (self.http_version,self.status))
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 389, in _write
    self.stdout.write(data)
  File "/usr/lib/python2.7/socket.py", line 324, in write
    self.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
  error: [Errno 104] Connection reset by peer
----------------------------------------
Exception happened during processing of request from ('58.33.144.118', 53268)
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     150, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 640, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------

任何人都可以提出一些建议来找出原因,谢谢。

4

2 回答 2

4

runserver使用域名而不是 IP运行:

python manage.py foobar.com:8000

请记住,您绝对不应该runserver在生产中使用:

请勿在生产环境中使用此服务器。它没有经过安全审计或性能测试。(这就是它会一直存在的方式。我们的业务是制作 Web 框架,而不是 Web 服务器,因此改进此服务器以使其能够处理生产环境超出了 Django 的范围。)

于 2013-10-10T16:01:35.730 回答
0

已经很久了,但我想我应该把这个写下来给有同样问题的其他人。

因为域名不是中国的北安(备案),ISP 阻止了访问这台服务器。

于 2016-10-24T07:02:22.280 回答