uwsgi部署django项目

时间:2021-07-13 21:05:21

一、更新系统软件包

yum update -y

 

二、安装软件管理包及依赖

yum -y groupinstall "Development tools" yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

 

三、yum安装python36

yum install -y python36 python36-devel

 

yum安装报错修改epel.repo

 uwsgi部署django项目

 

四、pip3

python36安装时默认安装pip3

yum install -y pip3

pip install django==1.11.8

pip install pymysql

pip install requests

将django项目拷贝至/www/目录下,测试项目运行是否正常,运行以下命令:

python3 ./manage.py runserver 127.0.0.1:8000

 

五、pip安装uwsgi

pip3 install uwsgi

 

/www/project根目录下创建Django项目名myDjango的myDjango.xml文件,内容为:

<uwsgi>

<socket>127.0.0.1:8001</socket><!-- 内部端口,自定义 -->

<chdir>/www/myDjango</chdir><!-- 项目路径 -->

<module>myDjango.wsgi</module>

<processes>4</processes> <!-- 进程数 -->

<daemonize>uwsgi.log</daemonize><!-- 日志文件 -->

</uwsgi>

 

uwsgi -x 'uwsgi.xml'

报错:uwsgi: invalid option -- 'x'

原因:centos下,在没有安装libxml2时,pip安装的uwsgi无法支持xml格式的配置文件

解决:

yum install libxml*

pip uninstall uwsgi

pip install uwsgi

注意删除 ~/.cache/pip pip安装缓存文件

 

六、nginx配置

server {

listen 8000;

server_name localhost;

 

#charset koi8-r;

#access_log /var/log/nginx/host.access.log main;

location / {

#proxy_pass http://tomcatServer;

include uwsgi_params;

uwsgi_pass 127.0.0.1:8001;

#uwsgi_param UWSGI_SCRIPT myDjango.wsgi;

#uwsgi_param UWSGI_CHDIR /root/myDjango;

}

location /static {

alias /www/myDjango/static;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

}