gunicorn 启动django

【Django】如何使用gunicorn部署django程序 Django程序有很多方式部署,不同系统采取的方式也不一样。使用gunicorn启动Django的服务可以提高并发能力。使用gunicorn部署django程序有很多方式,本片博客是本人用的比较多的方式,一键更新主要是为了节省时间。 阅读详情

 gunicorn.conf.py


import logging
import logging.handlers
from logging.handlers import WatchedFileHandler
import os
import multiprocessing

bind = "127.0.0.1:8000"   #绑定的ip与端口
backlog = 512                #监听队列数量,64-2048
worker_class = 'sync' #使用gevent模式,还可以使用sync 模式,默认的是sync模式
workers = 4 # multiprocessing.cpu_count()    #进程数
threads = 16 #multiprocessing.cpu_count()*4 #指定每个进程开启的线程数
loglevel = 'info' #日志级别,这个日志级别指的是错误日志的级别,而访问日志的级别无法设置
access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"'

accesslog = "-"  #访问日志文件,"-" 表示标准输出
errorlog = "-"   #错误日志文件,"-" 表示标准输出

proc_name = 'eashop'   #进程名

启动命令: 

 /root/python/bin/gunicorn  -c gunicorn.conf.py EA_Shop.wsgi:application
#EA_Shop 是有wsgi.py的目录层次

nginx.conf

server {
       listen 80;
       server_name xxx.xxx.com;
       client_max_body_size 50m;
      location /static {
     alias /*/static/;
     }
      location / {
               proxy_set_header x-Real-IP $remote_addr;
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_set_header Host $http_host;
               proxy_pass http://localhost:8000;
               #include uwsgi_params;
               #uwsgi_pass 127.0.0.1:8000;
               #proxy_pass_header Server;
                ##### 支持websocket
                proxy_redirect off;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
}
}

 

部署Django应用:使用Gunicorn和Nginx构建高效的生产环境 在Python Web开发中,Django是一个广受欢迎的高级Web框架,它鼓励快速开发并采用了明确的设计。然而,当Django应用准备从开发环境迁移到生产环境时,需要一个更加稳定和高效的部署解决方案。本文将详细介绍如何使用Gunicorn作为WSGI服务器和Nginx作为反向代理服务器,来部署一个Django应用。 阅读详情

相关推荐

宝塔面板使用docker+nginx+gunicorn部署Django项目实战教程

执行完这句命令后,静态资源会被收集到STATIC_ROOT所指定的目录中(如上图所示),django-simpleui的相关样式文件也会被一并收集到static目录中。如过不执行此操作,项目部署成功上线后,将无法看到图片、css、js等静态资源。我们可以看到,docker容器中有两个正在运行的镜像,一个是nginx:latest,一个是app-web,并且app-web是通过gunicorn的方式部署的。接下来我们可以通过命令的方式查看项目是否成功运行中。执行完此行命令,就代表我们的项目部署成功了。

m0_46219714的博客 2949

上线flask记录

上线flask记录

moyuanbomo的博客 1158

nginx+gunicorn Django项目部署:gunicorn开机自启动

承接django部署nginx+gunicorn 云服务器阿里云ubuntu16.04 1.新建.service文件 位置:/usr/lib/systemd/system 文件名:自定义(如项目名.service) -内容 [Unit] After=syslog.target network.target remote-fs.target nss-lookup.target [Service]...

Cganger的博客 897

Gunicorn启动Django服务

使用 Gunicorn 来运行 Django 项目可以提升性能,特别是在生产环境中。Gunicorn 是一个 Python WSGI HTTP 服务器,适合用于在多个工作进程中运行 Python 的 Web 应用。

全幼稚园最可爱 1230

[南大ICS-PA2] 字符串处理函数和printf实现

[南大ICS-PA2] 程序、运行时环境与AM 字符串处理函数和printf实现

qq_42474104的博客 2991

树莓派34/100 - Pico读取MPU6050加速度和陀螺仪传感器数据

树莓派Pico连接MPU-6050模块(三轴陀螺仪+三轴加速度),读取运动姿态数据。

申龙斌的程序人生 5097

如何使用gunicorn来启动Django项目

相信熟悉Django的小伙伴,一定都知道经典的python manage.py runserver 这个命令来启动,但是在实际项目中,我们一般不能或者不会使用这种方式来启动,那么要怎么处理呢? 接下来,我们来介绍一种现在比较流行的方式:gunicorn方式来启动。 首先,在我们的代码目录中新建一个虚拟环境: virtualenv -p /usr/local/pyenv/shims/python venv 然后,进入虚拟环境中: source venv/bin/activate pip...

Seagull的专栏 2232

AG32VF407直流电流采集仪设计:从1uA到10A宽范围采样与FPGA加速方案

本文详细介绍了基于AG32VF407芯片的直流电流采集仪设计方案,实现了从1uA到10A的宽范围采样。方案采用低噪声电源、精密运放调理、高速比较器自动档位切换及高精度ADC同步采样,并重点阐述了利用AG32VF407片内FPGA实现硬件加速以提升性能的架构思路,为精密电流测量提供了完整的硬件与FPGA加速解决方案。

weixin_33245447的博客 315

gunicorn结合django启动后台线程

preload 为True的情况下,会将辅助线程或者进程开在master里,加重master的负担(master最好只是用来负责监听worker进程) django应用的gunicorn示例:只在主线程里开启后台线程,worker里不启动后台线程 gunicorn -w 5 --preload -b 127.0.0.1:8088 application_name.wsg...

weixin_30530939的博客 937

保姆级教程:手把手教你为裕泰微YT8521 PHY芯片编写Linux设备树(DTS)节点与驱动

本文提供了一份详细的保姆级教程,手把手教你为裕泰微YT8521 PHY芯片编写Linux设备树(DTS)节点与驱动。从基础配置到RGMII接口的特殊设置,再到驱动开发的关键步骤和调试技巧,帮助开发者快速掌握PHY芯片的移植与开发。

weixin_33734785的博客 344

STM32外部中断与事件机制深度解析:从硬件触发到软件响应

本文深入解析STM32外部中断与事件机制,从硬件触发到软件响应的完整流程。通过对比中断和事件的应用场景、响应速度及配置方法,帮助开发者优化嵌入式系统设计,特别适合需要低功耗或高实时性的项目。

weixin_29175469的博客 419

django部署 gunicorn 自动启动gunicorn说明,systemctl

自动启动gunicorn说明 博主原帖: 14 - 使用 Nginx 和 Gunicorn 部署 Django 博客我看评论里面博主用的是Ubuntu 14的系统,所以可以用upstart的方式写脚本自动启动gunicorn,而在Ubuntu 16系统中已经没有upstart了,而是采用的systemd的方式。我参考了评论...

从零开始学习python --zeropython 1096

淘宝扫码登录避坑指南:如何避免异地登录风控并稳定获取Cookie(附Python代码)

本文深入解析了淘宝扫码登录的风控机制,提供了从环境仿真到代码实现的完整避坑指南。通过精细化伪装请求头、管理会话与IP策略,并附上Python示例代码,帮助开发者稳定获取Cookie,有效避免异地登录风控,实现自动化流程的可靠集成。

l6m7n8的博客 601

gunicorn 启动 Django 服务

使用 gunicorn 启动 Django 服务

zswdhy的博客 1312

YOLOv8改进 | Neck篇 | Slim-Neck替换特征融合层实现超级涨点 (又轻量又超级涨点)

本文给大家带来的改进机制是Slim-neck提出的Neck部分,Slim-neck是一种设计用于优化卷积神经网络中neck部分的结构。在我们YOLOv8中,neck是连接主干网络(backbone)和头部网络(head)的部分,负责特征融合和处理,以便提高检测的准确性和效率。亲测在小目标检测和大尺度目标检测的数据集上都有大幅度的涨点效果(mAP直接涨了大概有0.4左右。同时本文对Slim-Neck的框架原理进行了详细的分析,不光让大家会添加到自己的模型在写论文的时候也能够有一定的参照。

Snu77的博客 1万+

【UG\NX二次开发】使用内部函数展开和折叠工序导航器

NX二次开发-群精选」专栏收录了那些曾散落在聊天对话框里的精彩的知识分享,这都是被遗落的宝贵财富。让我们一起向大佬学习,充满激情地进步,不断超越自己。底部联系方式,欢迎您加入一起交流。​下次一定。

王牌飞行员_里海的博客 827

django+gunicorn配置和启动

django+nginx+gunicornn能解决的问题 django 是一个web框架,而非web server,直接用django拉起的web服务仅限于开发环境使用,生产环境不够稳定,也无法承受大量请求的并发,在生茶环境下需要使用服务器软件来处理各种请求,如Gunicorn、 Nginx或Apache,而Gunicorn+Nginx的搭配,好处多多,一方面基于Nginx转发Gunicorn服务,在生产环境下能补充Gunicorn服务在某些情况下的不足,另一方面,如果做一个Web网站,除了服务外,还有很多

On the road 3978

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

gunicorn启动django的坑

配置文件 bind = ‘0.0.0.0:80’ workers = 8 threads = 64 loglevel = ‘debug’ timeout=120 backlog = 1024 worker_class = ‘gevent’ daemon = True proc_name = ‘xxx’ pidfile = ‘./xx.pid’ accesslog = ‘./log/all.log’ errorlog = ‘./log/error.log’ 用上面的的方式启动的时候总是提示worker超时,即

敖尔其楞的专栏 1345

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Docker内启动gunicorn失败,django项目

[2021-09-28 20:41:48 +0800] [1765] [INFO] Worker exiting (pid: 1765) [2021-09-28 12:41:48 +0000] [1792] [INFO] Booting worker with pid: 1792 [2021-09-28 12:41:48 +0000] [1793] [INFO] Booting worker with pid: 1793 [2021-09-28 20:41:48 +0800] [1774] [ERROR].

qiangrx的专栏 1507

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【Django】gunicorn启动拆分settings后的django服务

之前将django的settings信息拆分成了base.py,develop.py,product.py。直接按照以前的启动方式来使用gunicorn启动服务,是启动不了了.会提示。在gunicorn官网里找到了解决方法。chatGPT提供的方法压根不能用。gunicorn加入一个。

10相濡以沫 434

linux + 宝塔面板 部署 django网站 启动方式:uwsgi 和gunicorn如何选择 ?

中文互联网上的django部署教程大多数都是教用uWSGI而不是Gunicorn。主要是很多早期教程、博客、书籍(包括《Python 编程:从入门到实践》)都采用了 uWSGI 为部署示例。导致后续内容沿用这套“模板式部署”。启动方式:uwsgi 和gunicorn如何选择?

bigcarp的专栏 860

ubuntu16.04自动系统启动gunicorn教程django

ubuntu16.04自动系统启动gunicorn教程django 博主原帖: 14 – 使用 Nginx 和 Gunicorn 部署 Django 博客我看评论里面博主用的是Ubuntu 14的系统,所以可以用upstart的方式写脚本自动启动gunicorn,而在Ubuntu 16系统中已经没有upstart了,而是采用的systemd的方式。我参考了评论里面_CindyL_的接System...

qq_38320702的博客 1686

django gunicorn启动配置

1.nginx配置 server{           listen port;  #对外提供端口       server_name server_name;      location / {          proxy_pass http://127.0.0.1:8888;          proxy_set_header Host $host;          prox

python小菜鸡的博客 5183

[Django基础] gunicorn启动django时静态文件的加载

目前在用nginx+gunicorn对django进行部署 当我用gunicorn -w 4 -b 127.0.0.1:8080 myproject.wsig:application启动django时访问主页却发现所有static文件夹下的静态文件都找不到,部分如下: Not Found: /static/js/app.min.js Not Found: /static/js/...

dcba1234568的博客 467

gunicorn启动django时静态文件的加载

目前在用nginx+gunicorn对django进行部署 当我用gunicorn -w 4 -b 127.0.0.1:8080 myproject.wsig:application启动django时访问主页却发现所有static文件夹下的静态文件都找不到,部分如下: Not Found: /static/js/app.min.js Not Found: /static/js/custom.js ...

python学习者的博客 2717
上一篇: 按位与、或、非、异或总结
下一篇: python生成树结构
唐僧不爱八戒
博客等级 码龄9年 158粉丝 84原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址