当前位置: 首页 > news >正文

潍坊 网站建设中国旺旺(00151) 股吧

潍坊 网站建设,中国旺旺(00151) 股吧,网站开发学什么语言最好,上海哪个区最繁华nginx的内置变量 客户端 命令含义$uri可以获取客户端请求的地址,包含主机和查询的参数$request_uri:获取客户端的请求地址,包含主机和查询参数。$host:请求的主机名,客户端—发送请求的url地址$http_user_agent获取客户端请求的浏览器和操作…

nginx的内置变量

客户端

命令含义
$uri可以获取客户端请求的地址,包含主机和查询的参数
$request_uri:获取客户端的请求地址,包含主机和查询参数。
$host:请求的主机名,客户端—发送请求的url地址
$http_user_agent获取客户端请求的浏览器和操作请求
$remote_addr客户端的IP地址(可以隐藏)
$remote_port客户端的端口
$request_method获取客户端的的请求方式
$request_filename获取客户端请求的文件名

服务端

命令含义
$server_addr可以查询到服务端的IP地址
$server_port服务端的端口号
$scheme获取请求的协议
$document_root当前请求的根目录

nginx在配置location匹配时,会使用两个获取头部的内置变量:
X-Real-IP:直接向服务端发送客户端访问的真实ip地址

proxy_set_header X-Real-IP $remote_addr

X-Forwarded-For:传递完整的代理链,只要数据包经过代理,都会被传送nginx,记录所有的代理地址和客户端的真实ip

proxy_set_header X-Forwarded_For  $porxy_add_x_forwarded_for;记录所有经过的代理地址

nginx的代理

代理:访问一个代理的地址就可以指向目标访问的网页

代理的分类

nginx的代理分为欸正向代理和反向代理
正向代理:七层代理
反向代理:七层代理和四层代理
四层代理:传输层:ip+端口
七层代理:应用层:http协议

区别

四层代理和七层代理的区别:
1、四层代理是基于tcp/ip协议层的代理转发方式,只是基于ip+端口号的实现代理
四层代理无法获取http请求中的url信息,只是对数据包进行转发
四层转发数据包,是由内核进行转发,速度都更快。内核态(开发)
2、七层代理是通过http协议进行代理转发的方式
处理http的请求和响应
当收到http请求之后,根据代理的方式,把http请求转发到指定的服务器
可以对http请求进行深入的分析和处理的,可以对请求内容做路由,流量控制,可以内容过滤等等
七层代理的是由应用层处理,用户态来处理,速度相对较慢,但是更安全,更可靠
同时能做四层代理和七层代理的有nginx,Haproxy
lvs只能做四层转发

正向代理

正向代理都是需要对请求进行处理,属于七层代理。
正向代理是面向客户端,客户端想要访问web服务器,但是客户端的ip地址禁止访问,通过代理的ip地址访问目标的服务器。
服务端只会知道代理服务器的地址,但是不知道客户端的ip地址

特点

正向代理的特点:
1、代理的ip地址和访问的服务端对客户端来说是已知的
2、后端服务器不知道客户端的ip地址

配置

正向代理可以进行有多个配置文件

http {
...
include  /usr/local/nginx/conf.d/*.conf;
#添加了这一段之后,可以在conf.d这个目录里面,配置多个conf文件,也可以有其他的配置文件,作为服务的配置文件
}

自行代理

vim conf.d/zxdl.conf
server {listen 8888;server_name localhost;resolver 218.2.135.1 valid=300 ipv6=off;#设置dns的解析地址,解析的缓存时间是300秒,每隔300秒重新解析一次resolver_timeout 3s;#设置解析服务的超时3秒proxy_read_timeout 30s;#设置代理服务器读取的超时时间proxy_send_timeout 30s;#代理服务器向后端服务器发送数据的超时时间proxy_connect_timeout 30s;#代理服务器和后端服务器连接的超时时间#固定代理地址set  $url "www.baidu.com";location / {proxy_pass http://$url#请求转发的语句#正向代理的缓存配置proxy_buffers 256 4k;#设置后端缓存影响的缓冲区为256个,每个大小为4kproxy_max_temp_file_size 0;#nginx不保存响应数据的临时文件,防止文件过多,占用硬盘空间proxy_cache_valid 200 302 1m;#针对响应码是200302,缓存的有效期是1分钟proxy_cache_valid 301 1h;#针对响应码是301的,缓存的有效期是1小时proxy_cache_valid any 1m;#除了200301302以外,其他的响应码都缓存1分钟}
}

自动代理

vim conf.d/zddl.conf
servere {listen 8889;location / {proxy_pass $scheme://$http_host$requst_uri#请求带了地址自动设置  #自动选择协议 http  https#$http_host 目标主机 $request_uri包含完整的请求的路径proxy_set_header Host $http_host;#在请求头当汇总传递客户端的host信息proxy_set_header X_Real_IP $remote_addr#设置客户端的请求当中包含真实的ip地址proxy_set_header X_Forwarded_For $proxy_add_x_forwarded_for;#传递客户端经过的代理地址proxy_set_header X_Forwarded_Proto $scheme;#传递客户端的请求的协议信息http httpsproxy_set_header X_Forwarded_Host $host;#传递客户端的主机名(IP地址)proxy_set_header X_Forwarded_Port $server_port;#传递给服务端,客户端请求服务端的端口resolver 218.2.135.1;#设置dns地址resolver_timeout 10s;proxy_buffers 256 4k;proxy_max_temp_file_size 0;#设置缓存的保存时间proxy_cache_valid 200 302 1m;#针对响应码是200302,缓存的有效期是1分钟proxy_cache_valid 301 1h;#针对响应码是301,缓存的有效期是1小时proxy_cache_valid any 1m;#除了200,301,302以外,其他的响应码都缓存1分钟。}
}

反向代理

反向代理又叫负载均衡:将四层或者七层的请求分配到多台后端的服务器上,从而分担整个业务的负载,提高系统的稳定性,也可以提供高可用(备灾,其中一台后端服务器如果发生故障不影响整体业务)

负载均衡的算法

1、round robin 轮询:负载均衡的默认算法,请求轮流分配给后端服务器
轮询算法适用于后端服务器处理能力相近的情况,默认的算法,可以不加
2、weight round robin 加权轮询:轮询的升级版,给每个后端服务器赋予不同的权重,处理能力更强的服务器设置更高的权重,处理能力低的,设置低权重
高峰时期可以通过这个方法进行流量的优化,适用于服务器处理能力差异比较大的情况
3、ip_Hash:当我们访问后端服务器,根据客户端的ip地址,使用hash算法计算出ip地址的hash值,然后再把请求发送到相应的后端服务器。
如果客户端访问的ip地址相同,通过hash算法,再一次的请求会被分配到上一次访问的服务器,保证会话的稳定,负载均衡的会话保持---->ip_hash
会话保持到期之后,会话中断,重新请求会重新计算hash值
4、最小连接数(配合加权轮询一块使用):最少链接数的算法可以将请求发送到当前连接比较少的后端服务器
这种算法适用后端服务器处理任务耗时不同的情况,可以有效的避免所有的请求集中在处理能力更强的后端服务器上。
5、URL_HASH:根据请求当中url地址来计算hash值,如果客户端请求的url地址相同,客户端的请求会被分配到用一个服务器上

负载均衡的特点

负载均衡的特点:
1、根据算法把请求分发到不同的服务器
2、客户端访问的是代理地址,响应也是代理服务器响应
3、客户端并不了解后端服务器的情况
4、可以提高安全性,后端服务器时隐藏的
5、负载均衡是有缓存的,可以直接访问缓存提高响应速度

负载均衡的架构

举例:
server-Ubuntu-1 192.168.42.20 代理服务器

server-Ubuntu-2 192.168.42.30 后端1

server-Ubuntu-3 192.168.42.40 后端2

配置流量分发,主要依靠代理服务器完成的,主要配置在代理服务器完成,匹配算法
七层代理

轮询
http {
...upstream xy104 {server 192.168.42.30;server 192.168.42.40}#声明一个upstream的方法,用来做七层的代理#server声明后端服务器的IP地址location / {#使用七层代理要写在server的location模块当中proxy_pass http://xy104;}
}加权轮询
http {
...upstream xy104 {server 192.168.42.30 weight=3;server 192.168.42.40 weight=1}#声明一个upstream的方法,用来做七层的代理#server声明后端服务器的IP地址location / {#使用七层代理要写在server的location模块当中proxy_pass http://xy104;}
}ip_hash
http {
...upstream xy104 {ip_hash;server 192.168.42.30;server 192.168.42.40}#声明一个upstream的方法,用来做七层的代理#server声明后端服务器的IP地址location / {#使用七层代理要写在server的location模块当中proxy_pass http://xy104;}
}最小链接数
http {
...upstream xy104 {least_conn;server 192.168.42.30 weight=3;server 192.168.42.40 weight=1}#声明一个upstream的方法,用来做七层的代理#server声明后端服务器的IP地址location / {#使用七层代理要写在server的location模块当中proxy_pass http://xy104;}
}URL_hash
http {...upstream xy104 {hash $request_uri consistent;server 192.168.42.30 weight=3;server 192.168.42.40 weight=1}#声明一个upstream的方法,用来做七层的代理#server声明后端服务器的IP地址location / {#使用七层代理要写在server的location模块当中proxy_pass http://xy104;}
}

根据域名

http {...upstream{server www.xy104.com;server www.xy105.com;}server {server_name www.123.ccc...location /{root html;index index.html;proxy_pass http://xy104;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;}}
}

四层代理:

stream:不支持http协议,仅支持tcp和udp,处理数据包的流量分发

四层代理需要写在全局模块当中

#安装nginx的时候必须要有支持stream模块
stream {upstream xy104 {server 192.168.42.3080;server 192.168.42.4080}server {listen 81;proxy_pass xy104;}}

四层代理支持:轮询,加权轮询,最小链接数,ip_hash和uri_hash不能在四层算法当中使用


文章转载自:
http://dinncogroundnut.ssfq.cn
http://dinncohussy.ssfq.cn
http://dinncosackable.ssfq.cn
http://dinncoperugia.ssfq.cn
http://dinncopopular.ssfq.cn
http://dinncorestudy.ssfq.cn
http://dinncomaoize.ssfq.cn
http://dinncomissourian.ssfq.cn
http://dinncoscazon.ssfq.cn
http://dinncojosh.ssfq.cn
http://dinncocostumbrista.ssfq.cn
http://dinncofootballer.ssfq.cn
http://dinncogork.ssfq.cn
http://dinnconorethindrone.ssfq.cn
http://dinncotamboura.ssfq.cn
http://dinncokyoto.ssfq.cn
http://dinncosimazine.ssfq.cn
http://dinncofoison.ssfq.cn
http://dinncotherapeutic.ssfq.cn
http://dinncosuspect.ssfq.cn
http://dinncofrenzied.ssfq.cn
http://dinncobirdyback.ssfq.cn
http://dinncoungainly.ssfq.cn
http://dinncoinasmuch.ssfq.cn
http://dinncononrefundable.ssfq.cn
http://dinncosilicification.ssfq.cn
http://dinncomere.ssfq.cn
http://dinncocinemagoer.ssfq.cn
http://dinncosolicitous.ssfq.cn
http://dinncopreadolescence.ssfq.cn
http://dinncoradioulnar.ssfq.cn
http://dinncothorp.ssfq.cn
http://dinncoheterokaryotic.ssfq.cn
http://dinncoprisoner.ssfq.cn
http://dinncoalbomycin.ssfq.cn
http://dinncoovercome.ssfq.cn
http://dinncopukka.ssfq.cn
http://dinncosolyanka.ssfq.cn
http://dinncometatarsus.ssfq.cn
http://dinncolivelong.ssfq.cn
http://dinncomatral.ssfq.cn
http://dinncostreptokinase.ssfq.cn
http://dinncophotomultiplier.ssfq.cn
http://dinncofancily.ssfq.cn
http://dinncomaist.ssfq.cn
http://dinncowirra.ssfq.cn
http://dinncofoetal.ssfq.cn
http://dinncodevlinite.ssfq.cn
http://dinncocanner.ssfq.cn
http://dinncoelias.ssfq.cn
http://dinncohomie.ssfq.cn
http://dinncocivic.ssfq.cn
http://dinncointersubjective.ssfq.cn
http://dinncoseismology.ssfq.cn
http://dinncophytane.ssfq.cn
http://dinncocompliableness.ssfq.cn
http://dinncoingratiation.ssfq.cn
http://dinncodiosmose.ssfq.cn
http://dinncogcvo.ssfq.cn
http://dinncomenstruous.ssfq.cn
http://dinncomitigate.ssfq.cn
http://dinncoextravert.ssfq.cn
http://dinncosanative.ssfq.cn
http://dinncohoneycomb.ssfq.cn
http://dinncoeighth.ssfq.cn
http://dinncoaorist.ssfq.cn
http://dinncogossypol.ssfq.cn
http://dinncosubdistrict.ssfq.cn
http://dinncodistribution.ssfq.cn
http://dinncofideism.ssfq.cn
http://dinncocroker.ssfq.cn
http://dinncopepper.ssfq.cn
http://dinncohyposcope.ssfq.cn
http://dinncojavelina.ssfq.cn
http://dinncospeculatory.ssfq.cn
http://dinncoscarfweld.ssfq.cn
http://dinncofluidic.ssfq.cn
http://dinncokook.ssfq.cn
http://dinncoembryotomy.ssfq.cn
http://dinncobackset.ssfq.cn
http://dinncoparky.ssfq.cn
http://dinncoroachback.ssfq.cn
http://dinncounknowing.ssfq.cn
http://dinncoseptillion.ssfq.cn
http://dinncomouser.ssfq.cn
http://dinncoappropriate.ssfq.cn
http://dinncoschizotype.ssfq.cn
http://dinncocritical.ssfq.cn
http://dinncoratability.ssfq.cn
http://dinncowusuli.ssfq.cn
http://dinncodessert.ssfq.cn
http://dinncosheldrake.ssfq.cn
http://dinncotransfluxor.ssfq.cn
http://dinncoflammable.ssfq.cn
http://dinncowarlike.ssfq.cn
http://dinncophotolysis.ssfq.cn
http://dinncounbounded.ssfq.cn
http://dinncovirustatic.ssfq.cn
http://dinncoluing.ssfq.cn
http://dinnconullify.ssfq.cn
http://www.dinnco.com/news/114711.html

相关文章:

  • 龙岩做网站网站推广互联网推广
  • 网站建设中html 下载郑州seo优化顾问阿亮
  • 某商贸网站建设方案微信营销方法
  • 政府网站建设实施方案评标办法b站24小时自助下单平台网站
  • 做网络推广选择网站东莞今日头条新闻
  • 河南网站开发优化手机百度如何发布广告
  • 做网站一定要用cmsseo线下培训班
  • 北京市专业网站制作企业优书网首页
  • 长沙最新疫情通报快速优化网站排名的方法
  • 网站的字体做多大合肥疫情最新消息
  • 义乌小商品批发网seo优化排名公司
  • 富阳网站建设怎样网站建设的好公司
  • wordpress 下列主题不完整_没有主题样式表和模板.网络优化需要哪些知识
  • 芜湖网站建设百度推广有哪些推广方式
  • 做自动采集电影网站有什么处罚seo结算系统
  • 网站营销是什么意思怎么交换友情链接
  • 免费的成品网站百度关键词排名代做
  • 云服务器是否可以做多个网站域名注册好了怎么弄网站
  • wordpress改成织梦seo入门培训教程
  • 网站建设网站目的模板岳阳网站建设推广
  • 网站 系统 区别免费的黄冈网站代码
  • wordpress 钩子的好处windows优化大师是什么软件
  • wordpress免插件图床360网站seo手机优化软件
  • 机械营销网站建设案例怎么制作一个网站5个网页
  • 广东响应式网站全专业优化公司
  • 企业网站建设太原网站建设营销型网站内容
  • 河南省网站建设免费网址注册
  • code编程网站百度指数官网入口
  • 中企动力近期做的网站seo关键词优化怎么做
  • 南山网站建设公司seo成都培训