框架5--nginx安装部署 下(web服务)
框架5--nginx安装部署 下(web服务)
1、提纲
1、Nginx虚拟主机
- 基于多IP的方式
- 基于多端口的方式
- 基于多域名的方式
2、日志配置
Nginx有非常灵活的日志记录模式,每个级别的配置可以有各自独立的访问日志。日志格式通过log_format命令定义格式
3、Nginx访问控制模块
4、Nginx访问认证模块
5、Nginx状态监控模块
nginx -V 查看nginx的所有模块
2、Nginx虚拟主机
1、基于多IP的方式
[root@web01 conf.d]# cat game2.conf
server {
listen 80;
server_name 192.168.15.7;
location / {
root /opt/Super_Marie;
index index.html;
}
}
server {
listen 80;
server_name 172.16.1.7;
location / {
root /opt/tank;
index index.html;
}
}
2、基于多端口的方式
[root@web01 conf.d]# cat game3.conf
server {
listen 80;
server_name 192.168.15.7;
location / {
root /opt/Super_Marie;
index index.html;
}
}
server {
listen 81;
server_name 192.168.15.7;
location / {
root /opt/tank;
index index.html;
}
}
3、基于多域名的方式
[root@web01 conf.d]# cat game4.conf
server {
listen 80;
server_name www.game.com;
location / {
root /opt/Super_Marie;
index index.html;
}
}
server {
listen 80;
server_name www.game1.com;
location / {
root /opt/tank;
index index.html;
}
}
3、Nginx日志
网站状态码是500的比例
网站的访问来源
网站排错
$remote_addr : 客户端IP
$http_x_forwarded_for : 真实的客户端IP(在反向代理中生效)
4、Nginx访问控制模块
- ngx_http_access_module
允许或者拒绝某些IP访问
deny : 拒绝
allow :允许
案例1:允许192.168.15.1访问,不允许其他IP访问
allow 192.168.15.1;
deny all;
案例2:允许192.168.15.0这个网段访问,不允许其他网段访问
allow 192.168.15.0/24;
deny all;
案例3:只允许通过VPN来访问
allow 172.16.1.81;
deny all;
- ngx_http_auth_basic_module
访问之前需要登录
1、安装httpd-tools
[root@web01 ~]# yum install httpd-tools -y
2、生成用户名密码文件
[root@web01 ~]# htpasswd -c /etc/nginx/auth chenyang
New password:
Re-type new password:
Adding password for user chenyang
3、将文件路径加入Nginx配置
[root@web01 ~]# vim /etc/nginx/conf.d/game4.conf
auth_basic "Welcome To Login";
auth_basic_user_file /etc/nginx/auth;
4、重启Nginx
[root@web01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 ~]# systemctl restart nginx
- ngx_http_autoindex_module
展示目录索引。
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
autoindex_format json;
5、Nginx状态监控模块
监控Nginx运行状态。
[root@web01 conf.d]# cat game5.conf
server {
listen 80;
server_name 192.168.15.7;
location / {
stub_status;
}
}
6、访问连接控制模块
1、控制Nginx连接数
1、安装ab测试命令
yum install httpd-tools -y
2、ab 参数
-n : 总共需要访问多少次
-c : 每次访问多少个
[root@web01 conf.d]# cat game5.conf
# limit_req_zone $remote_addr zone=one:10m rate=1r/s;
limit_conn_zone $remote_addr zone=addr:10m;
server {
listen 80;
server_name 192.168.15.7;
# limit_req zone=one burst=5;
limit_conn addr 1;
location / {
root /opt/Super_Marie;
index index.html;
}
}
2、控制Nginx访问量
1、连接池
limit_req_zone $remote_addr zone=one:10m rate=1r/s;
声明连接池 变量 名称 连接池的大小 速率
2、限制数
案例1:要求每秒只能有一个访问。
[root@web01 conf.d]# cat game5.conf
limit_req_zone $remote_addr zone=one:10m rate=1r/s;
server {
listen 80;
server_name 192.168.15.7;
limit_req zone=one burst=5;
location / {
root /opt/Super_Marie;
index index.html;
}
}
框架5--nginx安装部署 下(web服务)的更多相关文章
- Nginx安装部署与测试
场景:项目需要部署在生产环境中,这些新的工具都需要在生产环境中去实践练习.有时间再部署一套ELK的日志分析系统,这样的系统才算具有一定的应用价值. 1 Nginx安装 用root用户安装,采用源代码编 ...
- hue框架介绍和安装部署
大家好,我是来自内蒙古的小哥,我现在在北京学习大数据,我想把学到的东西分享给大家,想和大家一起学习 hue框架介绍和安装部署 hue全称:HUE=Hadoop User Experience 他是cl ...
- nginx 作为静态资源web服务
Nginx作为静态资源web服务 静态资源web服务-CDN场景 Nginx资源存储中心会把静态资源分发给“北京Nginx”,“湖南Nginx”,“山东Nginx”. 然后北京User发送静态资源请求 ...
- Nginx作为静态资源web服务之防盗链
Nginx作为静态资源web服务之防盗链 首先,为什么需要防盗链,因为有些资源存在竞争对手的关系,比如淘宝的商品图片,不会轻易的让工具来爬虫爬走收集.但是如果使用防盗链,需要知道上一个访问的资源,然后 ...
- Nginx作为静态资源web服务之跨域访问
Nginx作为静态资源web服务之跨域访问 首先了解一下什么是跨域 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器施加的安全限制. 所谓同源是指,域名,协议,端口均相 ...
- Nginx作为静态资源web服务之文件读取
Nginx作为静态资源web服务之文件读取 文件读取会使用到以下几个配置 1. sendfile 使用nginx作为静态资源服务时,通过配置sendfile可以有效提高文件读取效率,设置为on表示启动 ...
- nginx上部署python web
nginx上部署python web http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
- 通过 DynamicLinq 简单实现 N-Tier 部署下的服务端数据库通用分页
通过 DynamicLinq 简单实现 N-Tier 部署下的服务端数据库通用分页 YbSoftwareFactory 的 YbRapidSolution for WinForm 插件使用CSLA.N ...
- Nginx之静态资源WEB服务
本篇主要记录学习Nginx的静态资源WEB服务的几种常见的功能记录学习 Nginx开发常用的命令 nginx -tc /etc/nginx/nginx.conf vim /etc/nginx/conf ...
随机推荐
- 关闭SpringBoot logo图标
public static void main(String[] args) {// SpringApplication.run(LicenseApp.class, args); //关闭Spring ...
- Shell 中的 expect 命令
目录 expect 介绍 expect 安装 expect 语法 自动拷贝文件到远程主机 示例一 示例二 示例三 示例四 expect 介绍 借助 expect 处理交互的命令,可以将交互过程如 ss ...
- js获取设备公网ip + 服务器根据公网ip 获取IP信息
1.前言 本来呢,想实现js定位功能,最少定位到城市,一开始,使用的是搜狐的api直接获取数据,可是,有时候搜狐不可靠,只能得到 公网ip,其他信息无用,就像这样 2.既然这样,还不如我自己请求自己的 ...
- centos 目录结构
bin -----存放命令的目录(bin目录是快捷方式)是/usr/bin的快捷方式 sbin ----只有root用户才能使用的命令 etc ----系统服务的配置文件 /usr/local --- ...
- spring-data-jpa ----OneToMany 一对多
环境搭建 导入依赖 maven3.6.3 <properties> <spring.version>5.2.5.RELEASE</spring.version> ...
- day 16 int *p; scanf("%d",p);问题
(1).以下不能用于描述算法的是[A] (A).E-R图 (B).伪代码 (C).计算机语言 (D).流程图 分析:E-R图也称实体-联系图,提供了表示实体类型.属性和联系的方法,用来描述现实世界的概 ...
- Git 基本操作指南
Git 基本操作指南 内容概要 这个作业属于哪个课程 2022面向对象程序设计 这个作业要求在哪里 2022面向对象程序设计寒假作业1 这个作业的目标 Git & Github 作业正文 如下 ...
- linux 安装 elasticsearch 步骤及问题解决方案
1.下载安装包并上传至服务器 2.解压至当前文件夹 tar -xzvf xxx.tar.gz 3.配置JDK 如果服务器上已经配置了JDK,则在解压后的elasticsearch 文件夹的bin 目录 ...
- rocketmq实现延迟队列精确到秒级实现方案3-时间轮和秒级文件实现
时间轮和秒级文件实现原理图 这种方案比较简单实现,通过秒级时间,建立对应的文件夹,只要相同的时间超时的消息,就在同一个目录,通过msgid保证文件不重复,等到了时间后,就扫描对应的文件夹的文件,发送到 ...
- rocketmq实现延迟队列精确到秒级实现方案1-代理实现
简单的来说,就是rocketmq发送消息到broker的时候,判断是否定时消息, 如果是定时消息,将消息发送到代理服务(这个是一个独立的服务,需要自己开发,定时地把消息发送出去), 当然了消息用什么来 ...