Centos部署django服务nginx+uwsgi的方法
1.安装python3
yum-yinstallwgetgccmakezlib-develreadline-develbzip2-develncurses-develsqlite-develgdbm-develxz-develtk-developenssl-devel wgethttps://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz xz-dPython-3.6.1.tar.xz tar-xvfPython-3.6.1.tar cdPython-3.6.1 ./configure--prefix=/usr/local/python3.6--enable-optimizations make makeinstall ln-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
sudorpm-Uvhhttp://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm sudoyuminstall-ynginx sudosystemctlstartnginx.service
通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页面进行测试
3.下载代码,上传到服务器的/var/www目录
4.安装依赖
pip3installdjango pip3installuwsgi ln-s/usr/local/python3/bin/uwsgi/usr/bin/uwsgi3
5.独立运行进行测试
cd/var/www/dexundjango python3manage.pyrunserver0.0.0.0:8014
测试通过后,Ctrl+C停止运行
6.uwsgi
sudomkdir-p/etc/uwsgi/sites sudomkdir-p/var/log/uwsgi cd/etc/uwsgi/sites sudovi/etc/uwsgi/sites/mysite.ini
[uwsgi] socket=127.0.0.1:10000 chdir=/var/www/dexundjango module=mysite.wsgi:application master=True pidfile=/tmp/project-master.pid vacuum=True max-requests=5000 daemonize=/var/log/uwsgi/mysite.log
7.nginx配置
vi/usr/local/nginx/conf/nginx.conf(根据本地的配置路径) find/-nameuwsgi_params来替换下面的uwsgi_params路径
server{ listen8014;#暴露给外部访问的端口 server_namelocalhost; charsetutf-8; location/{ include/usr/local/nginx/conf/uwsgi_params; uwsgi_pass127.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:-8515 uwsgi=/usr/bin/uwsgi3 api_conf=/etc/uwsgi/sites/mysite.ini case$1in start) echo-n"StartinguWsgi" nohup$uwsgi-i$api_conf>/var/log/uwsgi/project-api.log2>&1& echo"done" ;; stop) echo-n"StoppinguWsgi" killall-9uwsgi echo"done" ;; restart) $0stop $0start ;; show) ps-ef|grepuwsgi ;; *) echo-n"Usage:$0{start|restart|stop|show}" ;; esac
chmod+x/etc/init.d/uwsgi chkconfig--adduwsgi chkconfiguwsgion
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。