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 ...
随机推荐
- FastDFD安装遇到的问题
如果按照步骤安装最后却发现 sudo service fdfs_trackerd start 启动不了,那么重启一下虚拟机就可以了
- Vue2.5开发去哪儿网App 第二章笔记
Vue完成 TodoList 1.默认方式 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- WebForm - cookie赋值乱码问题
cookie的值为中文时候,取cookie的值会出现乱码 解决办法:存取cookie时候先解码和编码 存cookie,进行编码: cookie.Value = HttpUtility.UrlEncod ...
- AndroidStudio打包apk,安装出现签名冲突--解决办法
Android UiAutomator2项目部署到jenkins上,实现自动打包,并自动push&安装到设备上 遇到问题: 可成功实现自动打包并push到设备上后,install -r 的时候 ...
- odoo开发笔记--模型中常用的方法
create方法在数据表中插入一条记录(或新建一个对象的resource)格式:def create(self,cr,uid,vals,context={})参数:vals:待新建记录的字段值,是一个 ...
- oracle RAC srvctl命令关闭节点实例的时候 不能正常执行
场景描述: [oracle@oracle01 admin]$ srvctl stop database -d oradb1 PRCD- : The resource for database ORAD ...
- Postgresql客户端不能远程连接数据库服务器 org.postgresql.util.PSQLException:
Postgresql安装完成之后,默认情况下是不允许远程客户端直接连接的,并且默认的监听配置文件里边,监听的服务器地址是127.0.0.1即:localhost 报如下错误: org.postgres ...
- 解决ubuntu安装系统默认没有创建root用户
安装ubuntu操作系统的时候,默认没有设置root账户的步骤!!! 这样在操作系统安装完成之后,就没有root用户, 一般,当前的普通用户,如果需要执行一些命令的时候,只要在命令前边加上sudo就行 ...
- Java代码调用Oracle的存储过程,存储函数和包
Java代码调用存储过程和存储函数要使用CallableStatement接口 查看API文档: 上代码: java代码调用如下的存储过程和函数: 查询某个员工的姓名 月薪 职位 create or ...
- 使用命令执行 sql 脚本文件
使用命令执行 sql 脚本文件 方法: 在 Windows 下使用 cmd 命令执行(或 Unix 或 Linux 控制台下)[Mysql的bin目录]\mysql –u用户名 –p密码 –D数据库名 ...