uwsgi+nginx+Ubuntu部署Django项目(阿里云)

如果使用默认的python   首先安装程序需要的包

apt-get install python-dev

apt-get install python-pip

apt-get install net-tools

apt-get install lsof

安装数据库

apt-get install mysql-server

apt-get install mysql-client

apt-get install libmysqlclient-dev

更新pip版本

pip install --upgrade pip

apt-get install openssh-server

apt-get install nginx

pip install uwsgi

修改Django项目的配置文件

DEBUG = False

ALLOWED_HOSTS = ["*"]

django的setting文件中,添加下面一行内容:

STATIC_ROOT = os.path.join(BASE_DIR, "static")

然后运行(收集admin后台的静态文件,如果不收集,将来访问linux的blog的admin将没有样式):

Python manage.py collectstatic

上传好项目之后

python3 manage.py runserver

确定项目能跑起来

进入项目目录 新建uwsgi.ini文件  touch uwsgi.ini,修改配置文件 注意socket端口一定要和nginx配置中的端口保持一致

/etc/nginx/conf.d/下创建项目配置文件xxx.conf,编辑配置文件,之一uwsgi_pass要和uwsgi.ini中的端口一致,配置完成后执行service nginx restart重启nginx服务

进入项目uwsgi所在目录,执行uwsgi --ini xxx.ini 启动项目

其中遇到了一个错误

no request plugin is loaded, you will not be able to manage requests.

you may need to install the package for your language of choice, or simply load it with --plugin.

查阅之后下载了 uwsgi-plugin-python

apt-get install uwsgi-plugin-python

但是并没有什么用。然后找了半天将其中的python改为python3 成功!

默认下载的是uwsgi-plugin-python2版本的

我用的是自带的python3.5

呐 就酱

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章