7、架构--location、LNMP架构、uwsgi部署、BBS项目部署
笔记
1、晨考
1、Nginx中常用的模块
autoindex
stub_status
allow 和 deny
basic
limit_conn
limit_req
2、配置步骤
1、创建连接池
2、调用
2、昨日问题
1、权限问题
2、端口占用问题
3、开机IP没了
3、今日内容
1、location
2、LNMP架构
4、location
使用Nginx Location可以控制访问网站的路径, 但一个server可以有多个location配置, 多个location的优先级该如何区分。
4.1、location匹配符号
| 匹配符 | 匹配规则 | 优先级 |
|---|---|---|
| = | 精确匹配 | 1 |
| ^~ | 以某个字符串开头 | 2 |
| ~ | 区分大小写的正则匹配 | 3 |
| ~* | 不区分大小写的正则匹配 | 3 |
| / | 通用匹配,任何请求都会匹配到 | 4 |
server {
listen 80;
server_name _;
location ~* /python {
default_type text/html;
return 200 "Location ~*";
}
location ~ /Python {
default_type text/html;
return 200 "Location ~";
}
location ^~ /python {
default_type text/html;
return 200 "Location ^~";
}
location = /python {
default_type text/html;
return 200 "Location =";
}
}
5、LNMP架构
LNMP是一套技术的组合,L=Linux、N=Nginx、M~=MySQL、P~=Python
首先Nginx服务是不能处理动态请求,那么当用户发起动态请求时, Nginx又是如何进行处理的。
1.静态请求:请求的内容是静态文件就是静态请求
1)静态文件:文件上传到服务器,永远不会改变的文件就是静态文件
2)html就是一个标准的静态文件
2.动态请求:请求的内容是动态的就是动态请求
1)不是真实存在服务器上的内容,是通过数据库或者其他服务拼凑成的数据
当用户发起http请求,请求会被Nginx处理,如果是静态资源请求Nginx则直接返回,如果是动态请求Nginx则通过uwsgi协议转交给后端的Python程序处理
5.1、uwsgi
因为nginx不支持wsgi协议,无法直接调用py开发的webApp。
在nginx+uWsgi+Django的框架里,nginx代理+webServer,uWsgi是wsgiServer,Django是webApp。
nginx接收用户请求,并判定哪些转发到uWsgi,uWsgi再去调用pyWebApp。
5.2、uwsgi服务部署
1、创建用户
[root@web01 opt]# groupadd django -g 888
[root@web01 opt]# useradd django -u 888 -g 888 -r -M -s /bin/sh
2、安装依赖软件
[root@web01 opt]# yum install python3 libxml* python-devel gcc* pcre-devel openssl-devel python3-devel -y
3、安装Django和uwsgi
[root@web01 opt]# pip3 install django
[root@web01 opt]# pip3 install uwsgi
4、创建项目
[root@web01 opt]# cd /opt
[root@web01 opt]# django-admin startproject linux
[root@web01 opt]# cd linux
[root@web01 opt]# django-admin startapp app01
[root@web01 linux]# vim linux/settings.py
ALLOWED_HOSTS = ['*']
DATABASES = {}
# 启动测试
[root@web01 linux]# python3 manage.py runserver 0.0.0.0:8000
5、编辑项目配置文件
[root@localhost ~]# cat /opt/linux/myweb_uwsgi.ini
[uwsgi]
# 端口号
socket = :8000
# 指定项目的目录
chdir = /opt/linux
# wsgi文件路径
wsgi-file = linux/wsgi.py
# 模块wsgi路径
module = linux.wsgi
# 是否开启master进程
master = true
# 工作进程的最大数目
processes = 4
# 结束后是否清理文件
vacuum = true
6、启动uwsgi
[root@web01 linux]# uwsgi -d --ini myweb_uwsgi.ini --uid 666
-d : 以守护进程方式运行
--ini : 指定配置文件路径
--uid : 指定uid
TCP 服务
7、编辑Nginx配置文件
[root@localhost ~]# cat /etc/nginx/conf.d/python.conf
server {
listen 80;
server_name py.test.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_read_timeout 2;
uwsgi_param UWSGI_SCRIPT linux.wsgi;
uwsgi_param UWSGI_CHDIR /opt/linux;
index index.html index.htm;
client_max_body_size 35m;
}
}
8、重启Nginx配置
systemctl restart nginx
6、部署BBS项目
1、部署数据库
[root@db01 ~]# yum install mariadb* -y
2、启动数据库
[root@db01 ~]# systemctl start mariadb
3、远程连接MySQL数据
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> CREATE DATABASE `bbs` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Query OK, 1 row affected (0.00 sec)
4、部署BBS
4.1、上传代码
[root@db01 ~]# unzip bbs.zip
[root@db01 ~]# mv bbs /opt/
4.2、数据库迁移
[root@web01 migrations]# pwd
/opt/bbs/app01/migrations
[root@web01 migrations]# rm -rf 00*
[root@web01 migrations]# rm -rf __pycache__/
[root@web01 migrations]# cd /opt/bbs/
[root@web01 bbs]# pwd
/opt/bbs
# 修改Django版本
[root@web01 bbs]# pip3 uninstall django
[root@web01 bbs]# pip3 install django==1.11
# 安装MySQL数据库插件
[root@web01 bbs]# pip3 install pymysql
# 修改数据连接
[root@web01 bbs]# vim bbs/settings.py
ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'bbs',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '172.16.1.61',
'PORT': 3306,
'CHARSET': 'utf8'
}
}
# 创建数据库迁移文件
[root@web01 bbs]# python3 manage.py makemigrations
# 数据库迁移
[root@web01 bbs]# python3 manage.py migrate
4.3、配置UWSGI
[root@localhost ~]# cat /opt/bbs/myweb_uwsgi.ini
[uwsgi]
# 端口号
socket = :8002
# 指定项目的目录
chdir = /opt/bbs
# wsgi文件路径
wsgi-file = bbs/wsgi.py
# 模块wsgi路径
module = bbs.wsgi
# 是否开启master进程
master = true
# 工作进程的最大数目
processes = 4
# 结束后是否清理文件
vacuum = true
[root@web01 bbs]# uwsgi -d --ini myweb_uwsgi.ini --uid 666
4.4、配置Nginx
[root@localhost ~]# cat /etc/nginx/conf.d/python.conf
server {
listen 80;
server_name bbs.test.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8002;
uwsgi_read_timeout 2;
uwsgi_param UWSGI_SCRIPT bbs.wsgi;
uwsgi_param UWSGI_CHDIR /opt/bbs;
index index.html index.htm;
client_max_body_size 35m;
}
}
[root@web01 bbs]# systemctl restart nginx
4.5、测试访问BBS
7、架构--location、LNMP架构、uwsgi部署、BBS项目部署的更多相关文章
- nginx之location、inmp架构详解、BBS项目部署
本期内容概要 location lnmp架构 部署BBS项目 内容详细 1.location 使用Nginx Location可以控制访问网站的路径 但一个server可以有多个location配置 ...
- BBS项目部署
1.准备 项目架构为:LNM+Python+Django+uwsgi+Redis (L:linux,N:nginx,M:mysql) 将bbs项目压缩上传到: /opt 在shell中直接拖拽 ...
- nginx+uwsgi+flask+supervisor 项目部署
环境 - Linux: Ubuntu 16.04 - uWSGI 2.0.18 - Flask 1.0.2 - supervisor 3.2.0 - nginx/1.8.1 首先区分几个概念 WSGI ...
- 学习VirtualEnv和Nginx+uwsgi用于django项目部署
以下叙述中用到的操作系统:Linux CentOS 6.X. 最近几天了解一下VirtualEnv,Apache+Daemon mode,Nginx+uwsgi的概念,并且在项目中实验性部署了一下(目 ...
- BBS项目部署之数据库的处理
一 数据库的处理: 1.1上传bbs.sql(数据库中的数据) 1.2在mysql中创建bbs库,并导入数据库SQL脚本 在mysqld的文件夹中: mysql> create databas ...
- 【新手向】阿里云上ubuntu+flask+gunicorn+nginx服务器部署(二)项目部署
本项目实现的是类似于ins的图片分享网站.继续(一),当nginx的配置已修改好后,要在远程服务器上部署网站,只需要几个步骤: 1 前期准备 2 将运行网站的代码从github上下载过来 3 下载依赖 ...
- myeclipse部署web项目部署按钮无效
找到MyEclipse的工作路径,我的是“E:\Java”,到这个目录中去“\.metadata\.plugins\org.eclipse.core.runtime\.settings”找一个含有de ...
- LNMP 架构 与 部署 uwsgi 服务
内容概要 nginx 配置文件中 location 匹配符号 LNMP 架构 uwsgi 服务部署 内容详细 一.location 使用 Nginx Location 可以控制访问网站的路径,但一个 ...
- Location配置项及LNMP架构
目录 Location配置项及LNMP架构 Location location匹配符号 LNMP架构 UWSGI uwsgi服务部署 部署BBS项目 步骤 Location配置项及LNMP架构 Loc ...
随机推荐
- 在 CentOS 7 上安装 GitLab
1. 安装和配置必要的依赖库 sudo yum install -y curl policycoreutils-python openssh-server # the commands below w ...
- nvm安装vue-cli
使用nvm可以更换nodejs版本.方便不同项目的切换 1.安装nvm(本人提供版本为1.1.9,当前最新) ① 到官网自行下载 https://github.com/coreybutler/nvm- ...
- Servlet初级学习加入数据库操作(一)
需要的源代码地址: https://url56.ctfile.com/f/34653256-527822631-2e255a(访问密码:7567) 将页面中的数据逐步替换为数据库管理 准备一个连接数据 ...
- Layui table 学习笔记
templet:'<div>{{createrFormat(d.accounts.name)}}</div>' function createrFormat(o){ retur ...
- 制作JavaCV应用依赖的基础Docker镜像(CentOS7+JDK8+OpenCV4)
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- func-spring-boot-starter 快速上手
func-spring-boot-starter test 项目地址 func-spring-boot-starter项目地址: https://gitee.com/yiur/func-spring- ...
- day 21 C语
(1).有以下程序: 执行后的输出结果是[A] (A).256,1 (B).1,256 (C).255,1 (D).256,0 (2).以下选项中与(!a==0)的逻辑值不等价的表达式是[B] (A) ...
- 设置图片DPI
//image 可以先转换为 bitmap Bitmap bmp = new Bitmap(width, height); bmp.SetResolution(300, 300);
- 【刷题-PAT】A1108 Finding Average (20 分)
1108 Finding Average (20 分) The basic task is simple: given N real numbers, you are supposed to calc ...
- Message deduplication 这里的去重与你想的可能不一样|Apache Pulsar 技术系列
导语 Apache Pulsar 是一个多租户.高性能的服务间消息传输解决方案,支持多租户.低延时.读写分离.跨地域复制.快速扩容.灵活容错等特性.腾讯云内部 Pulsar工作组对 Pulsar 做了 ...