On production, I run the django project with
python3 manage.py runserver
Resulting:
Performing system checks...
System check identified no issues (0 silenced).
December 09, 2019 - 03:23:26
Django version 2.2.7, using settings 'myproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
I also tried python3 manage.py runserver 0.0.0.0:8000
But when I access it, the site is refused to connect.
(I tried 0.0.0.0:8000
, 127.0.0.1:8000
, site-url:8000
)
When I tunnel it via ngrok, it run smoothly. So I found out that the django project is already running but we can't access it from outside.
When I run sudo lsof -i -P -n | grep LISTEN
The result is:
sshd 890 root 3u IPv4 18590 0t0 TCP *:22 (LISTEN)
sshd 890 root 4u IPv6 18592 0t0 TCP *:22 (LISTEN)
apache2 6049 root 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6049 root 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
python3 6117 aina 4u IPv4 2896228 0t0 TCP 127.0.0.1:8000 (LISTEN)
apache2 6141 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6141 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
ngrok 6198 root 3u IPv4 2896574 0t0 TCP 127.0.0.1:4040 (LISTEN)
apache2 6383 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6383 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
apache2 6401 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6401 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
apache2 6417 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6417 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
apache2 6419 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6419 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
apache2 6420 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6420 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
apache2 6421 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6421 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
apache2 6512 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6512 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
apache2 6555 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6555 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
apache2 6693 www-data 4u IPv6 2895520 0t0 TCP *:80 (LISTEN)
apache2 6693 www-data 6u IPv6 2895524 0t0 TCP *:443 (LISTEN)
I tried to telnet to port 8000 by running
telnet 127.0.0.1 8000
The results is:
Connected to 127.0.0.1.
Escape character is '^]'.
As there is other project is running in server (a PHP application in Apache), i follow this question Run both Django and PHP application in Apache
But the site still can't be reached when I access it directly (not via ngrok). What should I do so the django can be accessed?