centos7下采用Nginx+uwsgi来部署django
之前写过采用Apache和mod_wsgi部署django,因为项目需要,并且想比较一下Nginx和Apache的性能,尝试采用Nginx+uwsgi的模式来部署django。
1、安装uwsgi以及Nginx
pip install uwsgi --目前的版本为2.0.15
yum install epel-release
yum install nginx* --目前的版本为1.10.2
2、测试
# test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"
uwsgi --http : --wsgi-file test.py
采用浏览器访问主机或者采用postman模拟get操作,如果出现"Hello World"即测试成功
3、测试django工程
django-admin startproject myself
uwsgi --http : --chdir /home/myself --module myself.wsgi
并在django工程的settings里边添加主机的ip地址,采用浏览器访问主机或者采用postman模拟get操作,如果出现django的欢迎页面,“It works!”即测试成功
4、写uwsgi.ini配置文件
#uwsgi.ini file
[uwsgi] # Django-related settings
# the base directory (full path)
chdir = /home/myself
# Django's wsgi file
module = myself.wsgi:application
# the virtualenv (full path)
#home = /path/to/virtualenv # process-related settings
# master
master = true
# maximum number of worker processes
processes =
# the socket (use the full path to be safe)
#socket = /home/myself/myself.sock
socket = 127.0.0.1:
# ... with appropriate permissions - may be needed
chmod-socket =
chown-socket = nginx:nginx
# clear environment on exit
vacuum = true
enable-threads = true
5、修改nginx配置文件
vim /etc/nginx/nginx/conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; events {
worker_connections 1024;
} http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048; include /etc/nginx/mime.types;
default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf; upstream django {
#server unix:/home/myself/myself.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first) ---socket
} server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location /static/ {
root /home/myself; ----project地址
} location / {
include uwsgi_params;
uwsgi_pass django; ----上面修改socket的位置
} error_page 404 /404.html;
location = /40x.html {
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
} # Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# } }
6、采用Systemd管理uwsgi
mkdir -p /etc/uwsgi/ini
mv /home/myself/uwsgi.ini /etc/uwsgi/ini/
vim /etc/systemd/system/uwsgi.service [Unit]
Description=uWSGI Emperor
After=syslog.target [Service]
ExecStart=/root/uwsgi/uwsgi --emperor /etc/uwsgi/ini
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all [Install]
WantedBy=multi-user.target
centos7下采用Nginx+uwsgi来部署django的更多相关文章
- ubuntu NGINX uwsgi https 部署Django 遇到的问题
搞了3天终于把Django成功部署到Ubuntu,记录一下: 引用来自泡泡茶壶: Ubuntu下的Nginx + Uwsgi + Django项目部署详细流程 前提说明: Django作为小程序的后端 ...
- centos7 下通过nginx+uwsgi部署django应用
1. 安装python3.6 1. 获取 wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz tar -xzvf Python- ...
- Nginx+uWsgi生产部署Django
部署得过程很简单,部署得核心在于,为什么要这样做,每一个参数代表什么意思,最终的目的是得了解,一些基概念性的东西. uWsgi简介 说Uwsgi之前,先说一下Wsgi. 什么是Wsgi? WSGI: ...
- flask部署:Ubuntu下使用nginx+uwsgi+supervisor部署flask应用
之前一直用的Centos或者Red hat,自从使用Ubuntu后,发现Ubuntu使用起来更方便,自此爱上Ubuntu. 一.从github上下载flask应用 1.我已经成功将自己编写好的应用上传 ...
- 在阿里云 Ubuntu上通过nginx+uwsgi服务器部署Django出现的502错误
https://blog.csdn.net/luojie140/article/details/76919471 https://blog.csdn.net/sinat_21302587/articl ...
- CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点 以下 ...
- Nginx 和 Gunicorn 部署 Django项目
目录 Nginx 和 Gunicorn 部署 Django项目 配置Nginx 安装配置Gunicorn 通过命令行直接启动 Gunicorn 与 uwsgi 的区别,用哪个好呢 Gunicorn u ...
- 学习笔记(1)centos7 下安装nginx
学习笔记(1)centos7 下安装nginx 这里我是通过来自nginx.org的nginx软件包进行安装的. 1.首先为centos设置添加nginx的yum存储库 1.通过vi命令创建一个rep ...
- django+nginx+uwsgi 项目部署
Django虽然自带一个Server,但只能作为开发时测试使用,我们需要一个可以稳定而持续的服务器对网站进行部署,比如Apache, Nginx, lighttpd等,本篇将利用nginx和uWSGI ...
随机推荐
- 将Python项目打包成EXE可执行文件(单文件,多文件,包含图片)
解决 将Python项目打包成EXE可执行文件(单文件,多文件,包含图片) 1.当我们写了一个Python的项目时,特别是一个GUI项目,我们特备希望它能成为一个在Windows系统可执行的EXE文件 ...
- jQuery Mobile Api
jQuery Mobile提供了使用Javascript与框架(html5)通信以及进行内容管理的API.下面介绍具体事件. 文档事件 mobileinit事件会在jQuery Mob ...
- odoo开发笔记--python获取当天时间
取得时间相关的信息的话,要用到python time模块,python time模块里面有很多非常好用的功能,你可以去官方文档了解下,要取的当前时间的话,要取得当前时间的时间戳,时间戳好像是1970年 ...
- idea 运行scala代码 报错:Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$ java.lang.NoClassDefFoundError: scala/Function0 Error: A JNI error has occurred, please check your installati
各种报错信息如下: java.lang.NoClassDefFoundError: scala/Function0 at java.lang.Class.getDeclaredMethods0(Nat ...
- 查漏补缺之开g的正则
当正则表达式开了挂,就会多一个g的修饰符,用于表示全局匹配.然而这个表达式却不仅仅是多了个g这么简单,它的方法也会发生改变.由于之前不是太了解,今天好好捋一下,且听我细细道来. 正则表达式的方法和属性 ...
- 微信小程序网络封装-简单高效
废话引言 小程序虽然出世很久了,但一直没怎么接触到小程序开发.吉他兴趣班老师想弄一个小程序发布课程信息和打卡功能,作为IT一员就自愿加入了这个小程序开发小组中.虽然小程序面向的是前端工程师,但作为移动 ...
- GO入门——1.基础
1 安装配置与命令 GOROOT:Go根目录 GOPATH:GO工作目录,其目录下需要建立一下三个子目录 bin :存放编译后生成的可执行文件 pkg :存放编译后生成的包文件 src :存放项目源码 ...
- 「每日一码」a&b赋值问题
每日一码 将每天看到的优秀的代码或者特别的实现,记录下来 a&b赋值问题 2019-2-18 var a = {n: 1}; var b = a; a.x = a = {n: 2}; Q&am ...
- Maven3路程(一)环境搭建
好长时间不用Java,今天看了下,Maven集成成主流了,在技术水平与日俱进的同时,感叹下IT行业必须有活到老学到老的精神. 先说下环境: Maven:Maven 3.0.5 解压后路径:F:\Mav ...
- redis学习(二) redis数据结构介绍以及常用命令
redis数据结构介绍 我们已经知道redis是一个基于key-value数据存储的数据结构数据库,这里的key指的是string类型,而对应的value则可以是多样的数据结构.其中包括下面五种类型: ...