django+uwsgi+nginx的部署
1.下载与项目对应的django版本
pip3 install django==1.11.16 -i https://pypi.douban.com/simple/
2.用django内置的wsgi模块测试项目是否可以正常运行
python manage.py runserver 0.0.0.0:8080
3.下载uwsgi--此文所用版本:2.0.17.1
pip install uwsgi
4.测试uwsgi是否可以正常使用
1>测试文件test.py
def application(env, start_response):
start_response('200 OK',[('Content-Type', 'text/html')])
return [b'Hello world'] # Python3
2>测试语句
uwsgi --http 0.0.0.0:8080 --wsgi-file test.py
3>选做:可以直接命令测试django项目是否可以用uwsgi运行
切换到django的项目根目录中
[root@VM_0_3_centos day18_crm]# ls crm day18_crm manage.py nohup.out rbac README3 script static templates [root@VM_0_3_centos day18_crm]# pwd /data/day18_crm
注意:运行之前必须收集django项目的静态文件 --如果你的项目是每个APP下都有static文件夹的话
python manage.py collectstatic
uwsgi --http 0.0.0.0:8080 --file day18_crm/wsgi.py --static-map=/static=static
5.在django项目根目录中创建uwsgi.ini,将uwsgi参数写到配置文件中,后续与nginx配合
1>文件内容如下
[uwsgi]# uwsgi +django直接用的时候web端口号 #http= :9000 #niginx将动态请求代理回此端口号 socket=0.0.0.0:8080 #项目目录 chdir= /data/day18_crm #wsgi.py wsgi-file=day18_crm/wsgi.py processes=4 #进程 threads=2 #线程 stats =:9191 #服务停止的时候清除 socket环境 vacuum=true
6.用uwsgi启动django
1>正常启动
uwsgi --ini uwsgi.ini
2>后台挂起式启动
nohup uwsgi uwsgi.ini &
7.下载安装nginx--此文所用版本:nginx version: nginx/1.12.2
1>下载
yum -y install nginx
2>测试--查看xx.xx.xx.xx:80 nginx是否正常
systemctl start nginx.service
8.nginx配置
1>在django项目根目录创建uwsgi_params(注意文件名字不要错),改成777的权限,文件内容如下
uwsgi_param QUERY_STRING $query_string; uwsgi_param REQUEST_METHOD $request_method; uwsgi_param CONTENT_TYPE $content_type; uwsgi_param CONTENT_LENGTH $content_length; uwsgi_param REQUEST_URI $request_uri; uwsgi_param PATH_INFO $document_uri; uwsgi_param DOCUMENT_ROOT $document_root; uwsgi_param SERVER_PROTOCOL $server_protocol; uwsgi_param REQUEST_SCHEME $scheme; uwsgi_param HTTPS $https if_not_empty; uwsgi_param REMOTE_ADDR $remote_addr; uwsgi_param REMOTE_PORT $remote_port; uwsgi_param SERVER_PORT $server_port; uwsgi_param SERVER_NAME $server_name;
2>切换到nginx服务
cd /etc/nginx/conf.d/
3>创建配置文件--crm_nginx.conf
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 0.0.0.0:8080; # for a web port socket (we'll use this first) 与uwsgi.ini的socket ip保持一致
}
# configuration of the server
server {
# the port your site will be served on 服务访问的时候的IP xx.xx.xx.xx:8000/crm/login
listen 8000;
# the domain name it will serve for
server_name 0.0.0.0; # substitute your machine's IP address or FQDN 服务器IP
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
#location /media {
# alias /path/to/your/mysite/media; # your Django project's media files - amend as required
# }
location /static {
alias /data/day18_crm/static; # your Django project's static files - amend as required 收集的静态文件目录
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django; #代理块
include /data/day18_crm/uwsgi_params; # the uwsgi_params file you installed 与nginx通信用的,在django的根目录中存在的文件
}
}
4>查看django项目根目录文件
[root@VM_0_3_centos day18_crm]# ls crm day18_crm manage.py nohup.out rbac README3 script static templates uwsgi.ini uwsgi_params (俩个重要的文件)
9.启动nginx
1>启动
systemctl start nginx.service
2>查看现在需要的端口是否都启动
netstat -tunlp
tcp 0 0 0.0.0.0:9191 0.0.0.0:* LISTEN 20406/uwsgi tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 20406/uwsgi #动态文件交给uwsgi处理 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12460/nginx: master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 16787/sshd tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 12460/nginx: master #niginx处理静态文件的端口 tcp6 0 0 :::3306 :::* LISTEN 14978/mysqld tcp6 0 0 :::80 :::* LISTEN 12460/nginx: master udp 0 0 0.0.0.0:68 0.0.0.0:* 880/dhclient udp 0 0 172.27.0.3:123 0.0.0.0:* 550/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 550/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 550/ntpd udp 0 0 0.0.0.0:44221 0.0.0.0:* 22821/ntpdate udp 0 0 0.0.0.0:59948 0.0.0.0:* 880/dhclient udp6 0 0 :::41081 :::* 880/dhclient udp6 0 0 :::123 :::* 550/ntpd
3>再收集一遍静态文件
注意:一定要在django的settings.py中需要配置static根目录
STATIC_ROOT = os.path.join(BASE_DIR,'static')
python manage.py collectstatic
django+uwsgi+nginx的部署的更多相关文章
- 阿里云 centos7 django + uWSGI+Nginx + python3 部署攻略
centos7+nginx+python3+django+uwsgi配置Django 项目部署 1.租的服务器(选择centos)的话,需要在阿里云后台控制台开放几个端口,克隆一下已开放的端口,t ...
- Django部署,Django+uWSGI+nginx+Centos部署
说明:系统是在windows上开发的,使用django1.11.4+python3.6.3开发,需要部署在centos6.4服务器上. 第一步:在Centos6.4上安装Python3.6.2 安装请 ...
- Django+uwsgi+Nginx安装部署
安装 安装Nginx Nginx是最流行的高性能HTTP服务器. 安装pcre: wget https://sourceforge.net/projects/pcre/files/pcre/8.37/ ...
- django+uwsgi+nginx+sqlite3部署+screen
note:可通过该命令查找文件未知 sudo find / -name filename 一:项目(github) ssh root@server ip # 连接你的服务器 git ...
- Django+Uwsgi+Nginx项目部署文档
一.基本环境搭建 1)查看服务器 [root@Myjumpserver ~]# cat /etc/sysconfig/selinux SELINUX=disabled SELINUXTYPE=targ ...
- docker简单使用+django+uwsgi+nginx项目部署
使用docker 搭建 centos7 环境: 主机环境:windows 10专业版 一.安装docker Hub.docker.com官网下载 docker for windows 安装完成后,任务 ...
- centos7 nginx配置httpsCenos(6.6/7.1)下从源码安装Python+Django+uwsgi+nginx环境部署(二)
1.yum安装nginx 下载对应当前系统版本的nginx包(package) # wget http://nginx.org/packages/centos/7/noarch/RPMS/ngin ...
- CentOS7.4部署Python3+Django+uWSGI+Nginx
CentOS7.4部署Python3+Django+uWSGI+Nginx http://www.showerlee.com/archives/2590
- django项目在uwsgi+nginx上部署遇到的坑
本文来自网易云社区 作者:王超 问题背景 django框架提供了一个开发调试使用的WSGIServer, 使用这个服务器可以很方便的开发web应用.但是 正式环境下却不建议使用这个服务器, 其性能.安 ...
随机推荐
- vue路由传对象刷新会报错,数据丢失,用json字符串解决
变成json字符串,且加密 this.$router.push({name: response.body.PowerList[0].opPowerurl ,query :{ all: encodeUR ...
- Excel阅读模式/聚光灯开发技术序列作品之三 高级自定义任务窗格开发原理简述—— 隐鹤
Excel阅读模式/聚光灯开发技术序列作品之三 高级自定义任务窗格开发原理简述—— 隐鹤 1. 引言 Excel任务窗格是一个可以用来存放各种常用命令的侧边窗口(准确的说是一个可以停靠在类名为x ...
- NodeJs之文件上传
NodeJs之文件上传 一,介绍与需求 1.1,介绍 1,multer模块 multer用于处理文件上传的nodejs中间件,主要跟express框架搭配使用,只支持表单MIME编码为multipar ...
- NodeJs连接操作MongoDB数据库
NodeJs连接操作MongoDB数据库 一,介绍 MongoDB是一种文档导向数据库管理系统,由C++撰写而成.介绍如何使用 Node.js 来连接 MongoDB,并对数据库进行操作. Mongo ...
- centos关机与重启命令
Linux centos重启命令: 1.reboot 普通重启 2.shutdown -r now 立刻重启(root用户使用) 3.shutdown -r 10 过10分钟自动重启(root用户 ...
- 使用Crawler框架搭建自己的爬虫框架MyCrawler
自己写一个爬虫框架的目的: 完美架构 在实际的数据采集编码过程中,发现代码比较乱,抓取数据,存储数据的代码混杂在一起,为了构建比较完美的数据采集框架 敏捷开发 将数据采集进行标准流程化,每个标准流程都 ...
- ASP.NET Core 2.x On Ubuntu
安装.NET Core 首先需要安装.NET Core Runtime: https://www.microsoft.com/net/download 点击之后,根据您的Linux发行版不同,选择相应 ...
- [2019.03.22] Linux 学习心得(1)
本文关键词:shell 判断.grep正则表达式使用和贪婪匹配理解 1. if [ $a -le $b ], 一开始自学的时候我以为 [ ... ] 就是普通的,语法规定的结构,结果其实人家是&quo ...
- layui table默认选中指定行
表格默认选中行,在回调里写入 done: function (res, curr, count) { tableData = res.data; $("[data-field='id']&q ...
- docker添加阿里云专属镜像
阿里云镜像地址:https://link.zhihu.com/?target=https%3A//cr.console.aliyun.com/%23/accelerator 根据提示开启容器镜像服务, ...