django -- uwsgi+nginx部署
一、 安装nginx
How To Install Nginx on CentOS 7
- 添加epel扩展仓
sudo yum install epel-release
- 安装Nginx
yum install nginx
- 开启Nginx
sudo systemctl start nginx
如果防火墙拦截,可用下面的命令
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
浏览器打开
http://your_ip/
, 出现Welcome to nginx!说明安装成功开机启动项
systemclt enable nginx
服务器默认的根目录
/usr/share/nginx/html
, 服务器配置目录/etc/nginx/conf.d/
,文件要以.conf
结尾. 全局配置文件/etc/nginx/nginx.conf
二、安装uwsgi
pip install uwsgi
# 测试uwsgi 如:./Projects/Project/wsgi.py
cd Projects
uwsgi --http :8000 --module Project.wsgi
# or
uwsgi --http :8000 --file Project/wsgi.py
uwsgi 常用命令
uwsgi --chdir=/path/to/your/project \
--module=mysite.wsgi:application \
--env DJANGO_SETTINGS_MODULE=mysite.settings \
--master --pidfile=/tmp/project-master.pid \
--socket=127.0.0.1:49152 \ # can also be a file
--processes=5 \ # number of worker processes
--uid=1000 --gid=2000 \ # if root, uwsgi can drop privileges
--harakiri=20 \ # respawn processes taking more than 20 seconds
--max-requests=5000 \ # respawn processes after serving 5000 requests
--vacuum \ # clear environment on exit
--home=/path/to/virtual/env \ # optional path to a virtualenv
--daemonize=/var/log/uwsgi/yourproject.log # background the process
三、配置nginx
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name .example.com; # substitute your machine's IP address or FQDN
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 /path/to/your/mysite/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 /path/to/your/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}
加入nginx项目配置
sudo ln -s 你的目录/Mxonline/conf/nginx/uc_nginx.conf /etc/nginx/conf.d/
重启nginx
systemctl restart nginx
四、通过配置文件启动uwsgi
新建uwsgi.ini 配置文件, 内容如下:
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /path/to/Projects
# Django's wsgi file
module = Project.wsgi
# the virtualenv (full path)
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = 127.0.0.1:8000
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
virtualenv = .virtualenvs_dirs/venv_py
logto = /tmp/mylog.log
注:
chdir: 表示需要操作的目录,也就是项目的目录
module: wsgi文件的路径
processes: 进程数
virtualenv:虚拟环境的目录
参考: centos7 下通过nginx+uwsgi部署django应用
参考: Django + Uwsgi + Nginx 的生产环境部署
django -- uwsgi+nginx部署的更多相关文章
- virtualvenv+django+uWSGI+nginx 部署
原创博文 转载请注明出处! 1. virtualvenv 2. django 3. uWSGI 4. nginx 5. 踩坑记录 1. virtualvenv virtualvenv install ...
- django+uwsgi+nginx部署(非常详细)
django+uwsgi+nginx部署 1.介绍: 在网上看了很多教程,但自己部署了很久都没有成功,这篇博文记录自己所踩过得坑. 2.环境: Ubuntu 16.04.1 LTS (GNU/Linu ...
- Linux 集群概念 , wsgi , Nginx负载均衡实验 , 部署CRM(Django+uwsgi+nginx), 部署学城项目(vue+uwsgi+nginx)
Linux 集群概念 , wsgi , Nginx负载均衡实验 , 部署CRM(Django+uwsgi+nginx), 部署学城项目(vue+uwsgi+nginx) 一丶集群和Nginx反向代理 ...
- Django+uWSGI+Nginx 部署网站
Django 1.11设置 保证Django在本地调试没有问题: 当然这是前提^_^ 收集静态文件至指定文件夹 Django静态文件设置具体参考:https://docs.djangoproject. ...
- Ubuntu下Django+uWSGI+nginx部署
本文采用uwsgi+nginx来部署django 这种方式是将nginx作为服务端前端,将接受web所有的请求,统一管理,Nginx把所有的静态请求自己处理,然后把所有非静态请求通过uwsgi传递给D ...
- Django+Uwsgi+Nginx部署
一 uwsgi介绍 uWSGI是一个Web服务器,它实现了WSGI协议,uwsgi, http等协议. Nginx中HttpUwsgiMoule的作用是与uWSGI服务器进行交换 1 WSGI是一种W ...
- virtualvenv+django+uWSGI+nginx 部署 踩坑记录
原创博文 转载请注明出处! uwsgi: unrecognized option '--http:8089' uwsgi: unrecognized option '--http' uwsgi trk ...
- django+uwsgi+nginx 部署生产环境
一.Uwsgi安装 python3 -m pip install uwsgi cp /usr/local/python3/bin/uwsgi /usr/bin/ 测试 在django项目主目录下cre ...
- Ubuntu+Django+uWSGI+Nginx部署Django项目
安装uWSGI,pip依据自己要使用的python版本自行选择,python2.x版本使用pip进行安装,python3.x版本使用pip3进行安装 pip install uwsgi 配置uWSGI ...
- Django Uwsgi Nginx 部署
1.django的settings配置 参照博客 https://www.cnblogs.com/xiaonq/p/8932266.html # 1.修改配置 # 正式上线关闭调试模式, 不会暴露服务 ...
随机推荐
- 扩容swap空间
添加swap空间 适用场景: 安装系统时未分区swap,完成安装后又需使用swap的 swap空间不足,需要扩容 解决方法: 一.添加磁盘作为swap使用 添加磁盘 [root@test ~]# fd ...
- Java NIO系列教程(七) FileChannel
Java NIO中的FileChannel是一个连接到文件的通道.可以通过文件通道读写文件. FileChannel无法设置为非阻塞模式,它总是运行在阻塞模式下. 打开FileChannel 在使用F ...
- Oracle sys 用户无密码文件无法登录
1.安装时候,global database name 环境变量听ORACLE_SID不一致,生成的sys密码文件默认为global database name 一致,但在连接时候service n ...
- git remote: HTTP Basic: Access denied 错误解决办法
问题描述: git push 报 HTTP Basic: Access denied 错误 原因:本地git配置的用户名.密码与gitlabs上注册的用户名.密码不一致. 解决方案: 1. 如果账号密 ...
- [转]EasyUI 日期格式
本文转自:http://www.jeasyui.net/demo/512.html Different date formats are applied to different DateBox co ...
- AutoMapper之自定义解析
自定义解析 4.自定义解析 AutoMapper可以通过名称匹配等规则进行对象的映射,但是在实际的项目中,只是这样是远远不够的,比说我们需要名称不同的字段进行映射,或者需要再加一些逻辑处理.AutoM ...
- 50道sql练习题和答案
最近两年的工作没有写过多少SQL,感觉水平下降十分严重,网上找了50道练习题学习和复习 原文地址:50道SQL练习题及答案与详细分析 1.0数据表介绍 --1.学生表 Student(SId,Snam ...
- 2018 Google SEO 需要注意的点
1.RankBrain 是一种机器学习系统 - 会根据用户的行为进行,对网站排名. 用户在你的网页上停留多久(用户停留时长) 多大比例的用户点击了你的网页(点击率) Note: 之前Google 开发 ...
- Java 面试中遇到的坑
Java开发中很多人都不愿意修改自己以前的代码,看别人的代码更是无法忍受,当看到别人代码里面一些匪夷所思的写法实现时,恨不得找到负责人好好跟他谈谈心,那么你在开发中是不是也使用到以下几种实现呢. 1. ...
- 查看centos操作系统、java_jdk、hadoop位数
1.centos操作系统位数: file /bin/ls 此为64位 2.java jdk 位数: java -version 这个是64为的,若是没有,则默认为32位 3.hadoop位数: 进入h ...