Centos部署django服务nginx+uwsgi的方法

时间:2021-05-23

1.安装python3

yum -y install wget gcc make zlib-devel readline-devel bzip2-devel ncurses-devel sqlite-devel gdbm-devel xz-devel tk-devel openssl-develwget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xzxz -d Python-3.6.1.tar.xztar -xvf Python-3.6.1.tarcd Python-3.6.1./configure --prefix=/usr/local/python3.6 --enable-optimizationsmakemake installln -s /usr/local/python3.6/bin/python3 /usr/bin/python3 ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip3

这是通过编译的方式来安装的

输入 python3 –version 和 pip3 –version 进行测试

2. 安装nginx

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpmsudo yum install -y nginxsudo systemctl start nginx.service

通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页​面进行测试

3.下载代码,上传到服务器的/var/www 目录

4. 安装依赖

pip3 install djangopip3 install uwsgiln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi3

5. 独立运行进行测试

cd /var/www/dexundjangopython3 manage.py runserver 0.0.0.0:8014

测试通过后,Ctrl + C 停止运行

6.uwsgi

sudo mkdir -p /etc/uwsgi/sitessudo mkdir -p /var/log/uwsgicd /etc/uwsgi/sitessudo vi /etc/uwsgi/sites/mysite.ini[uwsgi]socket = 127.0.0.1:10000chdir=/var/www/dexundjangomodule=mysite.wsgi:applicationmaster=Truepidfile=/tmp/project-master.pidvacuum=Truemax-requests=5000daemonize=/var/log/uwsgi/mysite.log

7. nginx 配置

vi /usr/local/nginx/conf/nginx.conf (根据本地的配置路径)find / -name uwsgi_params 来替换下面的uwsgi_params路径server { listen 8014; #暴露给外部访问的端口 server_name localhost; charset utf-8; location / { include /usr/local/nginx/conf/uwsgi_params; uwsgi_pass 127.0.0.1:10000; # 必须和uwsgi.ini配置的端口一致 } location /static/ { alias /home/www/dexundjango/trade/static/; #项目静态路径设置 }

8. 启动uwsgi

uwsgi3 --ini /etc/uwsgi/sites/mysite.ini

9. 开机启动uwsgi

vi /etc/init.d/uwsgi#!/bin/bash# chkconfig: - 85 15uwsgi=/usr/bin/uwsgi3api_conf=/etc/uwsgi/sites/mysite.inicase $1 in start) echo -n "Starting uWsgi" nohup $uwsgi -i $api_conf >/var/log/uwsgi/project-api.log 2>&1 & echo " done" ;; stop) echo -n "Stopping uWsgi" killall -9 uwsgi echo " done" ;; restart) $0 stop $0 start ;; show) ps -ef|grep uwsgi ;; *) echo -n "Usage: $0 {start|restart|stop|show}" ;;esacchmod +x /etc/init.d/uwsgichkconfig --add uwsgichkconfig uwsgi on

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章