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-3.6.2.tgz -C /tmp
cd /tmp/Python-3.6.2/
2. 把Python3.6安装到 /usr/local 目录
./configure --prefix=/usr/local
make
make altinstall
3. 更改/usr/bin/python链接
ln -s /usr/local/bin/python3.6 /usr/bin/python3
2. maridb
1. 安装
sudo yum install mariadb-server
2. 启动, 重启
sudo systemctl start mariadb
sudo systemctl restart mariadb
3. 设置bind-ip
vim /etc/my.cnf
在 [mysqld]:
下面加一行
bind-address = 0.0.0.0
4. 设置外部ip可以访问
先进入mysql才能运行下面命令:
mysql 直接进入就行
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES
5. 设置阿里云的对外端口
视频中有讲解这部分
6. 安装mysqlclient出问题
centos 7:
yum install python-devel mariadb-devel -y
ubuntu:
sudo apt-get install libmysqlclient-dev
然后:
pip install mysqlclient
3. 安装nginx
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
4. 安装virtualenvwrapper
yum install python-setuptools python-devel
pip install virtualenvwrapper
编辑.bashrc文件
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
重新加载.bashrc文件
source ~/.bashrc 新建虚拟环境
mkvirtualenv mxonline 进入虚拟环境
workon mxonline 安装pip包
我们可以通过 pip freeze > requirements.txt 将本地的虚拟环境安装包相信信息导出来
然后将requirements.txt文件上传到服务器之后运行:
pip install -r requirements.txt
安装依赖包
5. 安装uwsgi
pip install uwsgi
6. 测试uwsgi
uwsgi --http :8000 --module MxOnline.wsgi
7. 配置nginx
新建uc_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 你的ip地址 ; # 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 你的目录/Mxonline/media; # 指向django的media目录
}
location /static {
alias 你的目录/Mxonline/static; # 指向django的static目录
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
}
8. 将该配置文件加入到nginx的启动配置文件中
sudo ln -s 你的目录/Mxonline/conf/nginx/uc_nginx.conf /etc/nginx/conf.d/
8. 拉取所有需要的static file 到同一个目录
在django的setting文件中,添加下面一行内容:
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
运行命令
python manage.py collectstatic
9. 运行nginx
sudo /usr/sbin/nginx
这里需要注意 一定是直接用nginx命令启动, 不要用systemctl启动nginx不然会有权限问题
10. 通过配置文件启动uwsgi
新建uwsgi.ini 配置文件, 内容如下:
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/bobby/Projects/MxOnline
# Django's wsgi file
module = MxOnline.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 = /home/bobby/.virtualenvs/mxonline
logto = /tmp/mylog.log
注:
chdir: 表示需要操作的目录,也就是项目的目录
module: wsgi文件的路径
processes: 进程数
virtualenv:虚拟环境的目录
workon mxonline
uwsgi -i 你的目录/Mxonline/conf/uwsgi.ini &
访问
http://你的ip地址/
centos7 下通过nginx+uwsgi部署django应用的更多相关文章
- 填坑!!!virtualenv 中 nginx + uwsgi 部署 django
一.为什么会有这篇文章 第一次接触 uwsgi 和 nginx ,这个环境搭建,踩了太多坑,现在记录下来,让后来者少走弯路. 本来在 Ubuntu14.04 上 搭建好了环境,然后到 centos7. ...
- Python3.6+nginx+uwsgi部署Django程序到阿里云Ubuntu16.04系统
Python3.6+nginx+uwsgi部署Django程序到阿里云Ubuntu16.04系统 这个是写好的Django程序在本地机运行的情况,一个查询接口. 准备工作 1.首先购买一台阿里云的EC ...
- nginx + uwsgi 部署 Django+Vue项目
nginx + uwsgi 部署 Django+Vue项目 windows 本地 DNS 解析 文件路径 C:\Windows\System32\drivers\etc 单机本地测试运行方式,调用dj ...
- CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点 以下 ...
- nginx + uwsgi 部署django项目
因项目需求,需要部署django项目,这里是基础的nginx配合uwsgi部署django,后续会采用docker部署的方式 环境: centos7 python3.5.4 django2.1.4 u ...
- centos7下采用Nginx+uwsgi来部署django
之前写过采用Apache和mod_wsgi部署django,因为项目需要,并且想比较一下Nginx和Apache的性能,尝试采用Nginx+uwsgi的模式来部署django. 1.安装uwsgi以及 ...
- CENTOS7 使用 Nginx + Uwsgi 部署 Django 项目
写在前面的话 最近总是见到有新学 Django 的朋友在部署自己的项目到 Linux 上面的时候运行不起来,所以就动手写了这篇博客. 对于不会搭建 Python 3 环境的朋友可以参考前面的博客[CE ...
- 生产环境使用Nginx+uwsgi部署Django
在本地运行django应用相对来说还是挺方便的,使用自带的runserver启动即可.如果在生产环境部署django,就要多考虑一些问题了.比如静态文件处理,安全,效率等等 在网上找到了不错的部署的教 ...
- Nginx + uWSGI 部署Django 项目,并实现负载均衡
一.uWSGI服务器 uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI ...
随机推荐
- VBA Excel WideCharToMultiByte Compile error on 64-bit System
Compile Error: The code in this project must be updated for use on64-bit systems. Please review and ...
- JVM介绍&自动内存管理机制
1.介绍JVM(Java Virtual Machine,Java虚拟机) JVM是Java Virtual Machine的缩写,通常成为java虚拟机,作为Java可以进行一次编写,到处执行(Wr ...
- BZOJ 2683: 简单题(CDQ分治 + 树状数组)
BZOJ2683: 简单题(CDQ分治 + 树状数组) 题意: 你有一个\(N*N\)的棋盘,每个格子内有一个整数,初始时的时候全部为\(0\),现在需要维护两种操作: 命令 参数限制 内容 \(1\ ...
- Splay树简单操作
前几天刚刚自学了一下splay,发现思路真简单实现起来好麻烦 先贴一下头文件 # include <stdio.h> # include <stdlib.h> # includ ...
- Js表单验证控件(使用方便,无需编码)-01使用说明
演示地址:http://weishakeji.net/Utility/Verify/Index.htm 开源地址:https://github.com/weishakeji/Verify_Js ...
- linux 初步试水_安装问题整理_1
linux的安装问题 预备: 我开始学习Linux使用的是<鸟哥的Linux私房菜 基础学习篇>,在书中提到的安装方法是光盘安装. 问题是,我没有光盘,这就很僵硬了. 通过网络的扫荡,我选 ...
- Redis之Hash
一.Redis之Hash简介 1. Hash是一个string类型的field和value的映射表,适合用于存储对象. 2. 每个hash可以存储232-1个键值对(40多亿). 二.Redis之Ha ...
- UML 中extend和include的区别
在UML用例图中有两种关系——包含和扩展,容易混淆,下面通过一张表来区别一下这两种关系.
- 在lamp上简单部署应用程序
前言:上文中,说到了lamp的基本原理,apache与php的三种交互模式,php与mysql(mariadb)的交互,一次完整lamp的请求. LAMP简单的部署之后,便能够简单的搭建自己的网站. ...
- 1111 WordReplace
#include<iostream> #include<string> using namespace std; int main() { string sa,sb,s; wh ...