ubuntu初始化python3+postgresql+uwsgi+nginx+django

python

安装

apt-get update

apt-get install postgresql

进入psql客户端

sudo -u postgres psql

创建数据库,修改默认用户密码

CREATE DATABASE dbname;

ALTER USER postgres WITH PASSWORD '123456';

\q

参考:http://www.cnblogs.com/zhangpengshou/p/5464610.html

跨服务器复制数据库

参考:http://www.cnblogs.com/xiangnan/p/6687029.html

二. Python3 + virtualenv + uwsgi + django 开发环境

安装pip

apt-get install build-essential python-dev python-pip python3-dev python3-pip libpq-dev

安装 virtualenv + uwsgi

pip install virtualenv

pip3 install uwsgi

参考:http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

建立环境

假设工程目录~/venv/app

virtualenv -p python3 venv

cd venv && source bin/activate

pip install django==1.9 jinja2 xlrd pillow pypinyin psycopg2

cd app

python manage.py collectstatic

python manage.py makemigrations

python manage.py migrate

最后退出virtualenv
deactivate

三. 其他

uwsgi守护进程

这样在使用诸如uwsgi uwsgi.ini的命令时,uwsgi进程将在后天进行.不占用当前shell.
daemonize = /some-path/access.log

uwsgi新开线程问题

需要 enable-threads = true

参考:http://stackoverflow.com/questions/15308718/how-can-i-use-uwsgi-web-py-to-run-background-function

uwsgi配置文件示例

[uwsgi]

uid = root

gid = root

chmod-socket = 666

chown-socket = root:root

#socket = 127.0.0.1:3000

#below in nginx: uwsgi_pass unix:///path-to-socket/proj.sock;

socket = /path-to-socket/proj.sock

chdir = /path-to-project/app

module = proj.wsgi

home = /path-to-project

chmod-socket = 666

env = DJANGO_SETTINGS_MODULE=proj.settings

master = true

processes = 1

vacuum = true

pidfile = /tmp/app

daemonize = /path-to-project/app/access.log

# uwsgi --reload /tmp/app

以上是 ubuntu初始化python3+postgresql+uwsgi+nginx+django 的全部内容, 来源链接: utcz.com/z/388364.html

回到顶部