I could run the server on port 8000
but when i try to use 80
with
python manage.py runserver myip:80
I get:
You don’t have permission to access that port.
If I use sudo python manage.py runserver myip:80
I get:
File "manage.py", line 14 ) from exc ^ SyntaxError: invalid syntax
If I write python
in the console I get version 3.5.5
and my env
is activated.
EDIT:
Using sudo python3 manage.py runserver myip:80
I get:
Traceback (most recent call last): File "manage.py", line 8, in <module> from django.core.management import execute_from_command_line ImportError: No module named 'django' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 14, in <module> ) from exc ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Advertisement
Answer
There are a couple of things going on here. First of all, only privileged users (e.g. root
or other users via sudo
) can bind to ports under 1024.
But more importantly, manage.py runserver
should never be used in production:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
I strongly advise you to set up a proper web server instead. If you search for “EC2 Django” you’ll find plenty of walkthroughs on how to do this properly.