无法连接到VirtualBox Ubuntu上的127.0.0.1:8000的django服务器

时间:2015-03-30 17:09:14

标签: python django virtualbox ubuntu-14.04

我正在使用Windows 7 Host OS在我的VirtualBox Ubuntu OS中开发一个django项目。执行命令python manage.py runserver后,服务器运行正常,但我无法通过浏览器访问127.0.0.1:8000。

我为我的互联网使用代理服务器。

浏览器是否尝试通过代理连接到localhost?

请帮帮我,我无法在网上找到任何解决方案。

(django-user)ankit@ankit-VirtualBox:~/django-user/mysite$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:80:a9:8f  
      inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
      inet6 addr: fe80::a00:27ff:fe80:a98f/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:4004 errors:0 dropped:0 overruns:0 frame:0
      TX packets:3354 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:2176660 (2.1 MB)  TX bytes:499447 (499.4 KB)

lo        Link encap:Local Loopback  
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:165 errors:0 dropped:0 overruns:0 frame:0
      TX packets:165 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:10788 (10.7 KB)  TX bytes:10788 (10.7 KB)

(django-user)ankit@ankit-VirtualBox:~/django-user/mysite$ wget -O-     http://localhost:8000/
--2015-03-30 23:14:09--  http://localhost:8000/
Connecting to 202.141.80.24:3128... connected.
Proxy request sent, awaiting response... 403 Forbidden
2015-03-30 23:14:09 ERROR 403: Forbidden.

(django-user)ankit@ankit-VirtualBox:~/django-user/mysite$ ps aux | grep python
ankit     2556  0.0  0.0  15940   920 pts/4    S+   23:16   0:00 grep --color=auto python
(django-user)ankit@ankit-VirtualBox:~/django-user/mysite$ netstat -tunlp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp6       0      0 ::1:631                 :::*                    LISTEN      -               
udp        0      0 0.0.0.0:59936           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:631             0.0.0.0:*                           -               
udp        0      0 0.0.0.0:25253           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:35502           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:25359           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:47976           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           2063/202.141.80.24:
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -               
udp        0      0 0.0.0.0:11638           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:32319           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:54922           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:3985            0.0.0.0:*                           -               
udp        0      0 127.0.1.1:53            0.0.0.0:*                           -               
udp        0      0 0.0.0.0:68              0.0.0.0:*                           -               
udp        0      0 0.0.0.0:34987           0.0.0.0:*                           -               
udp6       0      0 :::53662                :::*                                -               
udp6       0      0 :::5353                 :::*                                -               
udp6       0      0 :::55441                :::*                                -               

2 个答案:

答案 0 :(得分:1)

对于在上使用的计算机,<127> 127.0.0.1始终是localhost ,因此它不能用于在主机和来宾之间进行连接。您必须绑定到guest虚拟机中的“外部”接口,然后连接到主机中的“内部”接口,以便在两者之间进行通信。

答案 1 :(得分:1)

添加

ALLOWED_HOSTS = ['localhost','127.0.0.1']

到settings.py,做点什么?