本文共 2511 字,大约阅读时间需要 8 分钟。
#NOTE:
command start with "***(show_buiding)*** ", means run in virtualenv#安装mysql
参考:#安装virtualenv,用来配置多环境
参考:#在新环境中安装django
//bz I'm using python2.7 so install the old django//(show_buiding) $ python -m pip install "django<2" 装2以下(show_buiding) $ python -m pip install django //装2,准备在python3环境运行, 一定要注意,如果当前是python2直接这么装有问题,需要用python3装,也就是要切换虚拟环境//create new project(show_buiding) $ django-admin startproject show_building//run and check the server(show_buiding) $ python manage.py runserver 0.0.0.0:80//if want to add domain, then need to update the settings.py(show_buiding) $ cd show_building/show_building(show_buiding) $ vim settings.y
//add hostALLOWED_HOSTS = ['www.xxx.com' ,'xxx.com' ]//save and restart, it should be working.
#Link to mysql
##install mysql-python NOTE: if meet issue,(show_buiding) pip install mysql-python //刚试了下,出问题了,以后再改
##add config to
(show_buiding) $ vim settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'show_building', 'USER':'xxx', 'PASSWORD':'xxx', 'HOST':'localhost', 'PORT':'', }}
//migrate//python manage.py syncdb <- departure(show_buiding) $ ./manage.py migrate//then restart server again
untill now, the server is running.
#install gunicorn
(show_buiding) $ pip install gunicorn//at the same level of manage.py$ gunicorn show_building.wsgi:application --bind 0.0.0.0:8800 &//NOTE:: if the **8800** port can be accessed from outside, then you can open the web page like : http://www.xxx.com:8800
#Nginx
##install$ sudo apt-get install nginx
##Config
$ vim /etc/nginx/sites-available/default
server { listen 80; server_name xxable.com www.xxable.com fkdev.com www.fkdev.com; client_max_body_size 4G; access_log /root/web/show_buiding/show_building/logs/nginx-access.log; error_log /root/web/show_buiding/show_building/logs/nginx-error.log; location /static/ { alias /root/web/show_buiding/show_building/static/; } location /media/ { alias /root/web/show_buiding/show_building/media/; } location / { proxy_pass http://127.0.0.1:8800; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; } # Error pages error_page 500 502 503 504 /500.html; location = /500.html { root /root/web/show_buiding/show_building/static/; }}
##start
$sudo service nginx start
Untill now the server is running !!!
转载地址:http://bdcqi.baihongyu.com/