系统:AWS Ubuntu 18.04; python 2.7; Django 1.11.20
AWS security group:
(1) all trafic
or
(2)
costom TCP 1000-1100(应该也可以是其他的port)
HTTP 80 0.0.0.0/0
SSH 22 0.0.0.0/0
安装Django (也可以安装2.2)
pip install Django==1.11.20
检查安装情况
python -m django --version
或者直接
sudo apt-get update
sudo apt-get python-django
建立项目
sudo django-admin startproject myproject
cd myproject
运行服务器
尝试(1) python manage.py runserver
产生的127.0.0.1:8000 完全不能访问
尝试(2) python manage.py runserver 0.0.0.0:1090
找到EC2的public IP,在浏览器打开,之后加上port的数字(就是在security group里面打开的port)
既:x.x.x.x:1090 (x.x.x.x是aws instance的public ip)
得到提示 Invalid HTTP_HOST header: ‘x.x.x.x’. You may need to add u’x.x.x.x’ to ALLOWED_HOSTS
为了添加IP,修改myproject目录下 setting.py 中的ALLOWED_HOSTS为
ALLOWED_HOSTS = [‘x.x.x.x’]
重新使用尝试(2),可以加载网页
参考:
https://serverfault.com/questions/327380/beginner-installing-first-app-on-ec2-bitnami-stack/327381
https://www.youtube.com/watch?v=Kg29bvYyLSM
https://stackoverflow.com/questions/44184268/django-invalid-http-host-header-testserver-you-may-need-to-add-utestserver/44184583