笔记

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项目部署的更多相关文章

  1. nginx之location、inmp架构详解、BBS项目部署

    本期内容概要 location lnmp架构 部署BBS项目 内容详细 1.location 使用Nginx Location可以控制访问网站的路径 但一个server可以有多个location配置 ...

  2. BBS项目部署

    1.准备 项目架构为:LNM+Python+Django+uwsgi+Redis   (L:linux,N:nginx,M:mysql) 将bbs项目压缩上传到:  /opt 在shell中直接拖拽 ...

  3. 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 ...

  4. 学习VirtualEnv和Nginx+uwsgi用于django项目部署

    以下叙述中用到的操作系统:Linux CentOS 6.X. 最近几天了解一下VirtualEnv,Apache+Daemon mode,Nginx+uwsgi的概念,并且在项目中实验性部署了一下(目 ...

  5. BBS项目部署之数据库的处理

    一  数据库的处理: 1.1上传bbs.sql(数据库中的数据) 1.2在mysql中创建bbs库,并导入数据库SQL脚本 在mysqld的文件夹中: mysql> create databas ...

  6. 【新手向】阿里云上ubuntu+flask+gunicorn+nginx服务器部署(二)项目部署

    本项目实现的是类似于ins的图片分享网站.继续(一),当nginx的配置已修改好后,要在远程服务器上部署网站,只需要几个步骤: 1 前期准备 2 将运行网站的代码从github上下载过来 3 下载依赖 ...

  7. myeclipse部署web项目部署按钮无效

    找到MyEclipse的工作路径,我的是“E:\Java”,到这个目录中去“\.metadata\.plugins\org.eclipse.core.runtime\.settings”找一个含有de ...

  8. LNMP 架构 与 部署 uwsgi 服务

    内容概要 nginx 配置文件中 location 匹配符号 LNMP 架构 uwsgi 服务部署 内容详细 一.location 使用 Nginx Location 可以控制访问网站的路径,但一个 ...

  9. Location配置项及LNMP架构

    目录 Location配置项及LNMP架构 Location location匹配符号 LNMP架构 UWSGI uwsgi服务部署 部署BBS项目 步骤 Location配置项及LNMP架构 Loc ...

随机推荐

  1. spring-Ioc(二)学习笔记

    属性注入方式 设值注入:也就是set注入,通过setter方法注入 java Bean private ITestDao dao; public void setDao(ITestDao dao){ ...

  2. Linux设置新的服务器登录端口

    root用户登录服务器 22端口修改为22525,22端口也打开,以防新端口设置有问题,登录不上服务器 向防火墙中添加修改的端口 systemctl start firewalld firewall- ...

  3. 学习javaScript必知必会(1)~js介绍、函数、匿名函数、自调用函数、不定长参数

    一.简单了解一下JavaScript(js) 1.什么是js? js:是网景公司开发的,是基于客户端浏览器, 面向(基于)对象.事件驱动式的页面脚本语言. 2.什么场景下使用到js? 表单验证.页面特 ...

  4. C#获取http图片

    public Image GetHttpImage(string url) { var client = new HttpClient(); var uri = new Uri(Uri.EscapeU ...

  5. Spark-寒假-实验4

    1.spark-shell 交互式编程 (1)该系总共有多少学生: 执行命令: var tests=sc.textFile("file:///home/hadoop/studata/chap ...

  6. MacBookPro2021 M1-MAX电脑问题锦集

    MacBook2021 M1-MAXPro电脑问题锦集 问题1: 开启硬盘加密,开机闪屏 问题详述: 在系统偏好设置中,打开安全与隐私,在弹出窗口中切换到第二个页签(文件保险箱),启用文件保险箱功能, ...

  7. 【刷题-PAT】A1119 Pre- and Post-order Traversals (30 分)

    1119 Pre- and Post-order Traversals (30 分) Suppose that all the keys in a binary tree are distinct p ...

  8. 【转载】select case break引发的血案

    原文请看:select case break引发的血案 我也遇到了,浪费了一个多小时. 牢记: for { switch var1{ case "not match": go En ...

  9. manjaro20软件商店无法链接下载

    软件商店如果无法链接下载 解决方案1 可以使用terminal慢慢下载,.bashrc中配置代理 如果依然不行,检查网络设置代理是否为自动或者手动设置正确. 解决方案2 检查是否未设置中国社区源或者重 ...

  10. Centos配置yum本地源最简单的办法

    有关centos配置yum本地源的方法 一.前提 先连接镜像 然后在命令行输入如下命令 mount /dev/sr0 /mnt cd /etc/yum.repos.d/ ls 之后会看到如下的界面 二 ...