python做网站部署起来真的太麻烦了!
1 | apt-get update && apt-get upgrade |
3 | hostnamectl set-hostname django-server |
8 | 编辑host文件,在127.0.0.1下在加入以下这行,ctrl+X |
9 | 198.59.119.183 django-server |
15 | ssh coreyms@198.59.119.183 #重新登陆 |
切换到本地电脑
1 | ssh-keygen -b 4096 #使用默认路径 |
2 | scp -/.ssh/id-rsa.pub coreyms@198.58.119.183:-/.ssh/authorized_keys |
服务器上查看key
5 | sudo nano /etc/ssh/sshd_config |
8 | passswordAuthentication no |
10 | sudo systemctl restart sshd |
1 | sudo apt-get install ufw |
2 | sudo ufw default allow outgoing |
3 | sudo ufw default deny incoming |
布置django
本地
1 | source Desktop/django_env/bin/activate |
3 | pip freeze > requirements.txt |
5 | scp -r django_project coreyms@198.58.119.183:-/ |
server
2 | sudo apt-get install python3-pip |
3 | sudo apt-get install python3-venv |
4 | python3 -m venv django_project/venv #make viretual env |
7 | source venv/bin/activate |
8 | pip install -r requirements.txt |
9 | sudo nano django_project/settings.py |
11 | Allowed_host = [´198.58.119.183´] |
12 | static_Root = os.path.join(base_dir,´ static ´) #add this line |
13 | python manage.py collectstatic |
15 | python manage.py runserver 0.0.0.0:8000 |
访问198.58.119.183:8000,应该能访问了。
2 | sudo apt-get install apache2 |
3 | sudo apt-get install libapache2-mod-wsgi-py3 |
4 | cd /ect/apache2/sites-availabe/ |
6 | sudo cop 000- default .conf django_project.conf |
7 | sudo nano django_project.conf |
8 | #在 </virtualhost>前面加添加以下内容 |
9 | Alias / static /home/coreyms/django_project/ static |
10 | <Directory /home/coreyms/django_project/ static > |
14 | Alias /media /home/coreyms/django_project/media |
15 | <Directory /home/coreyms/django_project/media> |
19 | <Directory /home/coreyms/django_project/django_project> |
25 | WSGISciptAlias / /home/coreyms/django_project/django_project/wsgi.py |
26 | WSGIdaemonProcess django_app python-path=/home/coreyms/django_project python-home=/home/coreyms/django_project/venv/ |
27 | WSGIProcessGroup django_app |
30 | sudo a2ensite django_project |
31 | sudo a2dissite 000- default .conf |
32 | sudo chown :www-data django_project/db.sqlite3 |
33 | sudo chmod 664 django_project/db.sqlite3 |
34 | sudo chown :www-data django_project/ |
35 | sudo chmod 775 django_project/ |
36 | sudo chown -r :www-data django_project/media/ |
37 | sudo chmod -R 775 django_project/media/ |
39 | sudo touch /etc/config.json |
40 | sudo nano django_project/django_project/settings.py |
42 | sudo nano /etc/config.json |
#建立json文件
1 | sudo nano /etc/config.json |
3 | with open(´/etc/config.json´) as config_file: |
4 | config = json.load(config_file) |
5 | secret_key = config[´secret_key´] |
8 | Email_host_usr = config.get(´Email_user´) |
9 | Email_host_password = config.get(´Email_pass´) |
1 | sudo ufw delet allow 8000 |
3 | sudo service apache2 restart |
现在访问,应该可以访问了。
不过还没有包括绑定域名。
goolge: django deploy checklist