nginx+uwsgi+django环境部署部署
首科常昊技术部
Django框架部署文档:
硬件环境:阿里云ecs服务器8核心、16GB、10Mbps
环境结构:nginx+uwsgi+django
所需软件:python-3.6.1、pip3.6、mysql-5.1.73 nginx-1.6.3、
[root@shouke src]# yum install zlib-develbzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-develtk-devel [root@shouke ~]# yum -y install opensslopenssl-devel
编译安装python3.6.1 [root@shouke leslie]# tar zxvf Python-3.6.1.tgz -C /usr/src/ [root@shouke leslie]# cd /usr/src/Python-3.6.1/ [root@shouke Python-3.6.1]# ./configure--prefix=/usr/local/python --enable-shared CFLAGS=-fPIC [root@shouke Python-3.6.1]#make&&make install
##安装完python3.6过程中自动安装了pip工具
'''
#Collecting setuptools
#Collecting pip
#Installing collected packages: setuptools,pip
#Successfully installed pip-9.0.1setuptools-28.8.0
'''
现在输入python还是python2.6
[root@shouke ~]# python Python 2.6.6 (r266:84292, Jul 23 2015,15:22:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] onlinux2 Type "help","copyright", "credits" or "license" for moreinformation. >>>
将2.6python的程序备份
[root@shouke ~]# which python /usr/bin/python [root@shouke ~]# cd /usr/bin/ [root@shouke bin]# mv python python.bak
将3.6的python软链接到/usr/bin/python
[root@shouke bin]# ln -s/usr/local/python/bin/python3 /usr/bin/python [root@shouke bin]# python python: error while loading sharedlibraries: libpython3.6m.so.1.0: cannot open shared object file: No such fileor directory
缺少libpython3.6m.so.1.0 将python安装目录下的libpython3.6m.so.1.0链接到/usr/lib64库下
[
root@shouke bin]# ln -s/usr/local/python/lib/libpython3.6m.so.1.0 /usr/lib64/
可以使用了
[root@shouke bin]# python Python 3.6.1 (default, Oct 26 2017,11:49:35) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] onlinux Type "help","copyright", "credits" or "license" for moreinformation. >>> print("hello world") hello world >>>
现在yum无法使用了,因为yum是使用python解释器运行的,现在找不到原来版本的python了,所以无法运行了,
[root@shouke bin]# yumFile "/usr/bin/yum", line 30except KeyboardInterrupt, e:^ SyntaxError: invalid syntax[root@shouke bin]# which yum /usr/bin/yum
[root@shouke bin]# cat /usr/bin/yum
#!/usr/bin/python2.6 ##修改第一行为这样 import sys try:import yum except ImportError:print >> sys.stderr, """\ There was a problem importing one of thePython mod 。。。
yum可以使用了:
[root@shouke bin]# yum makecache Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile*base: mirrors.aliyuncs.com*epel: mirrors.aliyuncs.com*extras: mirrors.aliyuncs.com
安装 uwsgi
[root@shouke bin]#/usr/local/python/bin/pip3 install uwsgi Collecting uwsgiDownloadinghttp://mirrors.aliyun.com/pypi/packages/bb/0a/45e5aa80dc135889594bb371c082d20fb7ee7303b174874c996888cc8511/uwsgi-2.0.15.tar.gz(795kB)100% |████████████████████████████████| 798kB 58.5MB/s Installing collected packages: uwsgiRunning setup.py install for uwsgi ... done Successfully installed uwsgi-2.0.15
验证安装:
[root@shouke bin]#/usr/local/python/bin/uwsgi --version 2.0.15
安装django
[root@shouke ~]# /usr/local/python/bin/pip3install django Collecting djangoDownloadinghttp://mirrors.aliyun.com/pypi/packages/82/33/f9d2871f3aed5062661711bf91b3ebb03daa52cc0e1c37925f3e0c4508c5/Django-1.11.6-py2.py3-none-any.whl(6.9MB)100% |████████████████████████████████| 7.0MB 68.8MB/s Collecting pytz (from django)Downloadinghttp://mirrors.aliyun.com/pypi/packages/55/62/e7cd0e15b76062d298413f14bb4ec3cd8568a22d274427f9c3c7286969f4/pytz-2017.2-py2.py3-none-any.whl(484kB)100% |████████████████████████████████| 491kB 67.8MB/s Installing collected packages: pytz, django Successfully installed django-1.11.6pytz-2017.2
验证安装:
[
root@shouke ~]# python Python 3.6.1 (default, Oct 26 2017,11:49:35) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux Type "help","copyright", "credits" or "license" for moreinformation. >>> import django
>>> django.VERSION (1, 11, 6, 'final', 0)
输入url:8002验证。(提示服务器ip地址加入到允许访问的列表内)
[root@shouke demosite]# vim demosite/settings.py #修改此文件
[root@shouke demosite]# python manage.pyrunserver 0.0.0.0:8002
再次运行,访问成功:
部署项目:
将项目上传到服务器:
移动到项目/opt下面,并在/opt下面新建文件夹script
[root@shouke opt]# ls gitlab online_edit_script script
在script目录里新建uwsgi.ini配置文件
[root@shouke opt]# cd script/ [root@shouke script]# ls uwsgi.ini [root@shouke script]# vim uwsgi.ini
#uwsig使用配置文件启动
[uwsgi]
# 项目目录
chdir=/opt/online_edit_script/
# 指定项目的application
module=online_edit_script.wsgi:application
# 指定sock的文件路径
socket=/opt/script/uwsgi.sock
# 进程个数
workers=5
pidfile=/opt//script/uwsgi.pid
# 指定IP端口
http=127.0.0.1:9001
# 指定静态文件
static-map=/static=/opt/online_edit_script/static
# 启动uwsgi的用户名和用户组
uid=root
gid=root
# 启用主进程
master=true
# 自动移除unix Socket和pid文件当服务停止的时候
vacuum=true
# 序列化接受的内容,如果可能的话
thunder-lock=true
# 启用线程
enable-threads=true
# 设置自中断时间
harakiri=30
# 设置缓冲
post-buffering=4096
# 设置日志目录
daemonize=/opt/script/uwsgi.log
配置nginx:
服务器上nginx已经部署了,直接修改配置文件
server {server_name www.leslie.com;location /{include uwsgi_params; ##加载uwsgi支持模块uwsgi_connect_timeout 30; ##超时时间uwsgi_pass unix:/opt /script/uwsgi.sock; #转到uwsgi这个进程}location/static/ { ##静态文件nginx自己处理alias/opt/online_edit_script/static/;indexindex.html index.htm;} }
检测语法:
[root@shouke script]# /application/nginx/sbin/nginx -t nginx: the configuration file/application/nginx-1.6.3//conf/nginx.conf syntax is ok nginx: configuration file/application/nginx-1.6.3//conf/nginx.conf test is successful
安装mysql:
yum -y install mysql mysql-devel mysql-server mysql-client
pip3 install mysqlclient
修改配置文件将域名加入到允许访问的列表里面。
[root@shouke ~]# vim /opt/online_edit_script/online_edit_script/settings.py
初始化uwsgi
Uwsgi –ini /opt/script/uwsgi.ini
会生成一个进程监听本地的9001端口
tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 19214/uwsgi
重启nginx:
kill all nginx /usr/local/nginx/sbin/nginx
访问测试:
OK!
转载于:https://blog.51cto.com/lesliecheung/1976438
nginx+uwsgi+django环境部署部署相关推荐
- Nginx uWsgi Django环境搭建
2019独角兽企业重金招聘Python工程师标准>>> 由于一个监控项目(使用django开发)交接到所在项目组,需要了解python的web开发和环境搭建. 这里记录环境的搭建流程 ...
- Django 部署基础【使用 Nginx + uWSGI 的方式来部署来 Django】
本文主要讲解在 Linux 平台下,使用 Nginx + uWSGI 的方式来部署来 Django,这是目前比较主流的方式.当然你也可以使用 Gunicorn 代替 uWSGI,不过原理都是类似的,弄 ...
- Centos 6.5部署nginx+uwsgi+django
Centos 6.5部署nginx+uwsgi+django 一.安装python3,系统默认是python2.6 1.安装依赖软件 yum -y install sqlite-devel yum - ...
- nginx+uWSGI + django部署项目
项目部署 nginx+uWSGI + django 1. WSGI WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器(返回静态资源的就是web服务器,Nginx)如何与Web应用程序( ...
- Docker部署Angular+Nginx+uwsgi+Django项目
Docker部署Angular+Nginx+uwsgi+Django项目 0.前言 在开发部署时,容易遇到服务器环境不一致,多台服务重复部署操作过于繁杂的情况.这时可以采用Docker来提供一套统一的 ...
- Nginx+uWSGI+Django方法部署Django程序
在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.nginx把所有静态请求自己来处理(这是NGINX的强项).然后,NGINX将所有非静态请求通过u ...
- 微信抢票环境配置——nginx + uwsgi + django配置服务器
微信抢票环境配置--nginx + uwsgi + django配置服务器 1 uwsgi配置 2 http协议(80端口)下的nginx配置 1 uwsgi配置 安装uwsgi pip3 insta ...
- Docker搭建 Nginx+PHP+MySQL 环境并部署WordPress实践
本文给大家分享的是作者基于Docker搭建 Nginx+PHP+MySQL 环境并部署WordPress的详细过程,非常的全面,有需要的小伙伴可以参考下 Docker基于LXC实现了把软件封装到一个完 ...
- Ubuntu Nginx uwsgi django 初试
/*************************************************************************************** Ubuntu Ngin ...
最新文章
- Nature-2012-拟南芥根系微生物组的结构
- 推荐一个单元测试模拟框架:Nsubstitute
- android 字体加下划线,android自定义带下划线EditText解决文字压线的问题
- DigSci科学数据挖掘大赛-亚军方案分享
- java复制类mytool_MyTools
- Android开发之百度地图距离判断(判断定位位置是否在圆的范围内)
- [译]ASP.NET Core 2.0 带初始参数的中间件
- 智慧交通day04-特定目标车辆追踪03:siamese在目标跟踪中的应用-SiamRPN++(2019)
- java中连接mysql数据库_java中怎么连接mysql数据库
- mingw linux socket,MingW上编译WinSocket程序undefined reference to `WSAStartup@8'报错的解决办法...
- pyqt怎么button怎么链接_SEO内部链接怎么优化
- 基于物联网平台开发手机混合 App
- Blender全新毛发工具演示露出,预计9月份正式更新
- C语言实现平衡二叉树
- nmds与mds的区别_帮研网—科研共享平台——PCA、PCoA和NMDS有什么区别?
- jackson java用法_Jackson 使用方法总结
- 绝对免费搭建不限速私人网盘5T存储空间:Gearhost免费空间+OneIndex程序+Onedrive免费账号
- Android通知栏字体大小,Android通知栏介绍与适配总结(上篇)
- 循序搜寻法(使用卫兵)
- 【开源毕设】一款精美的家校互动APP分享——爱吖校推 [你关注的,我们才推](持续开源更新2)