uwsgi+django 配置
uwsgi+django
创建新的虚拟环境,且解决crm的环境依赖
在虚拟环境下安装uwsgi
pip3 install uwsgi
学习uwsgi命令,如何启动python应用
启动python web文件
创建一个test.py写入如下代码def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"] # python3
用uwsgi启动一个python web文件
指定8000端口启动 http服务
指定wsgi文件
uwsgi --http :8000 --wsgi-file test.py
用uwsgi启动django项目
uwsgi --http :9000 --module Alibab_crm.wsgiuwsgi加上热加载命令
uwsgi --http :8000 --module Alibab_crm.wsgi --py-autoreload=1使用uwsgi配置文件去启动项目
手动创建uwsgi.ini 配置文件
(alicrm) [root@s16ds Alibab_crm]# cat uwsgi.ini# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
#指定django的项目目录,第一层
chdir = /opt/Alibab_crm
# Django's wsgi file
#找到django的wsgi文件
#这里需要写项目的第二层目录Alibab_crm
module = Alibab_crm.wsgi
# the virtualenv (full path)
#填写虚拟环境的绝对路径
home = /root/Envs/alicrm
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 5
# the socket (use the full path to be safe
#指定socket协议,运行django,只能与nginx结合时使用
#指定socket协议,运行django,只能与nginx结合时使用
#指定socket协议,运行django,只能与nginx结合时使用
socket = 0.0.0.0:8000
#如果你没用nginx,只想自己启动一个http界面,用这个
#http = 0.0.0.0:8000 # ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
通过配置文件启动uwsgi
uwsgi --ini uwsgi.ini
收集django crm的静态文件
编辑crm的settings.py配置文件
写入如下代码# 定义django的静态资源根目录,便于用命令收集资源,存放的地儿
STATIC_ROOT="/opt/crm_static"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static') ]用命令收集静态文件
python3 manage.py collectstatic
配置nginx,反响代理django服务器,且解析静态文件
proxy_pass 仅仅是请求转发的参数,与uwsgi结合,还有跟高级的协议参数
修改nginx配置文件如下
server {
listen 80;
server_name s16chiji.com;
location / {
#root /opt/s16chiji;
#index index.html;
#使用uwsgi_pass 转发基于uwsgi协议的一个请求 uwsgi_pass 192.168.15.71:8000;
include /opt/nginx112/conf/uwsgi_params;
}
#配置一个url的入口,告诉django静态文件在哪里去找
#当请求url是 s16chiji.com/static/的时候
#就进行别名,nginx去/opt/crm_static下寻找js文件
location /static {
alias /opt/crm_static/;
}
#通过这个参数,定义错误页面的文件 ,当状态码是 404 400 401 时,返回40x.html页面
error_page 404 401 400 403 /40x.html;
}
此时nginx结合uwsgi 已经完成
记住这里推出虚拟环境,使用物理环境去运行
配置supervisor工具,管理django后台
- 这个东西只能用python2去实现
下载supervisor
easy_install supervisor
配置supervisor的配置文件,编写django任务
echo_supervisord_conf > /etc/supervisor.conf
编写运行django的任务
vim /etc/supervisor.conf
在最底行写入如下代码[program:s16alicrm]
command=/root/Envs/alicrm/bin/uwsgi --ini /opt/Alibab_crm/uwsgi.ini
autorestart=true
stopasgroup=true
killasgroup=true
启动suopersivod这个程序
启动服务端
supervisord -c /etc/supervisor.conf
通过客户端命令查看任务
supervisorctl -c /etc/supervisor.conf
学习supervisor管理命令
[root@s16ds alicrm]# supervisorctl -c /etc/supervisor.conf
s16alicrm RUNNING pid 5293, uptime 0:03:03
supervisor> stop all #停止所有任务
supervisor> start all #启动s所有任务
supervisor> status s16alicrm
uwsgi+django 配置的更多相关文章
- nginx +uwsgi + django配置
一 安装 nginx 二 安装 uwsgi ,pip install uwsgi 三 配置nginx 打开 nginx.conf文件, location / { # root html; # ind ...
- nginx uwsgi django 配置
用django框架,uwsgi服务器作为动态服务器,nginx作为静态资源服务器 配置uWSGI,在项目目录下创建uwsgi.ini文件: [uwsgi] #使用nginx连接时使用 socket=1 ...
- Nginx+UWSGI+Django配置全过程
重度参阅 原理+实战http://zhou123.blog.51cto.com/4355617/1688434 原理http://www.cnblogs.com/fnng/p/5268633.html ...
- Nginx+uWSGI+Django环境配置
通常项目会部署在虚拟环境,虚拟环境的使用可以参考这里,点击前往 当然你也可以直接部署,这里不多说. 一.安装uWSGI 1.通过pip安装 pip install uwsgi 这里只说明了一种安装方式 ...
- nginx+uWSGI+django+virtualenv+supervisor发布web服务器
nginx+uWSGI+django+virtualenv+supervisor发布web服务器 导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以 ...
- 12,nginx+uWSGI+django+virtualenv+supervisor发布web服务器
导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以及Web应用程序如何链接在一起以处理一个请求,(接收请求,处理请求,响应请求) 基于wsgi运行的框架 ...
- nginx+uWSGI+django+virtualenv+supervisor发布web服务器流程
导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以及Web应用程序如何链接在一起以处理一个请求,(接收请求,处理请求,响应请求)基于wsgi运行的框架有 ...
- Nginx+Python+uwsgi+Django的web开发环境安装及配置
Nginx+Python+uwsgi+Django的web开发环境安装及配置 nginx安装 nginx的安装这里就略过了... python安装 通常系统已经自带了,这里也略过 uwsgi安装 官网 ...
- 【uWSGI】实战之Django配置经验
uWSGI 是应用服务器,实现了uwsgi, wsgi等协议,可以运行wsgi 应用 uwsgi 是协议名 Django配置 下面是自己经常用的一个配置模板,基于1.9以上的版本使用的, 主要基于dj ...
随机推荐
- EWS 邮件提醒
摘要 之前做的邮件提醒的项目,最近需要优化,由于使用了队列,但即时性不是特别好,有队列,就会出现先后的问题,最近调研了exchange 流通知的模式,所以想使用流通知模式和原先的拉取邮件的方法结合,在 ...
- 关于sublimeText3 设置格式化代码快捷键的问题
sublime中自建的有格式化按钮: Edit -> Line -> Reindent 只是sublime并没有给他赋予快捷键,所以只需加上快捷键即可 Preference -& ...
- Expression<Func<T>>和Func<T>
以前用EF的时候,由于where的时候有Expression<Func<T>>和Func<T>两种查询条件,误用了Func<T>那个重载,后来还想通过f ...
- 从xml文件取值
假设有个 test.xml,包含以下字段: <config> <property name="login_protocol" value="http&q ...
- [亲测!超级简单] Centos 安装Python3.6环境
配置好Python3.6和pip3安装EPEL和IUS软件源 yum install epel-release -y yum install https://centos7.iuscommunity. ...
- js同时获取多个同name的input框的值
demo代码 <!doctype html> <html ng-app="a3_4"> <head> <title>表头排序< ...
- 截取URL的某个参数值
原文作者链接 https://www.jianshu.com/p/c9324d237a8e
- PHP 类文件的自动加载机制 __autoload()
如果一个类在多个脚本中都需要使用,可以将一个类的定义代码,单独的封装到一个文件中,这种文件也叫作类文件,在需要的时候,将整个文件载入进来即可! PHP在执行的时候,如果发现需要一个类(只要是和这个类相 ...
- VBoxManage翕令
VBoxManage list vms VBoxManage startvm dcsvr08 -type vrdp VBoxHeadless -startvm "dcsvr08" ...
- Oracle 远程链接oracle数据库服务器的配置
远程链接oracle数据库服务器的配置 by:授客 QQ:1033553122 原理: 一.Oracle客户端与服务器端的通讯机制 1.OracleNet协议 如下图所示,Oracle通过Oracle ...