Ankit
Ankit

Reputation: 27

Unable to connect to django server at 127.0.0.1:8000 on VirtualBox Ubuntu

I am working on a django project in my VirtualBox Ubuntu OS with Windows 7 Host OS. After executing the command python manage.py runserver the server runs fine, but I am unable to access 127.0.0.1:8000 through my browser.

I use a proxy server for my internet.

Is the browser trying to connect to localhost through the proxy?

Please help me out, I couldn't find any solution online.

(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                :::*                                -               

Upvotes: 0

Views: 3074

Answers (2)

Richard Octovianus
Richard Octovianus

Reputation: 180

does add

ALLOWED_HOSTS = ['localhost','127.0.0.1']

to settings.py, do the thing?

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798814

127.0.0.1 is always localhost for the machine it is being used on, so it cannot be used to connect between the host and the guest. You must bind to an "external" interface in the guest and then connect to the "internal" interface in the host in order to communicate between the two.

Upvotes: 1

Related Questions