1、更新系統軟件包html
yum update -ypython
2、安裝軟件管理包及依賴mysql
yum -y groupinstall "Development tools" yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-develnginx
3、yum安裝python36sql
yum install -y python36 python36-develdjango
yum安裝報錯修改epel.repocentos
4、pip3緩存
python36安裝時默認安裝pip3tomcat
yum install -y pip3socket
pip install django==1.11.8
pip install pymysql
pip install requests
將django項目拷貝至/www/目錄下,測試項目運行是否正常,運行如下命令:
python3 ./manage.py runserver 127.0.0.1:8000
5、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安裝緩存文件
6、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;
}
}