http proxy模块参数
http proxy模块参数
nginx功能的代理功能是是通过http proxy模块来实现的。默认在安装Nginx是已经安装了http proxy模块,可以直接使用。
http模块相关参数 |
说明 |
proxy_set_header |
设置http请求header项传给后端服务节点,例如:可实现让代理后端的服务节点获取访问客户端用户的真实IP地址 |
client_body_buffer_size |
用于指定客户端请求主体缓冲区大小,此处如果了解前面的http请求包的原理就好理解了 |
proxy_connect_timeout |
表示反向代理与后端节点服务器连接的超时时间,即发起握手等候相应超时时间 |
proxy_send_timeout |
表示代理后端服务器的数据回传时间,即在规定时间之内后端服务器必须传完所有的数据,否则Nginx将断开这个连接 |
proxy_read_timeout |
设置Nginx从代理的 后端服务器获取信息的时间,表示连接建立成功后,Nginx等待后端服务器的相应时间,其实是Nginx已经进入后端的排队之中等候处理的时间 |
proxy_buffer_size |
设置缓存区大小,默认该缓存区等于指令proxy_buffer设置的大小 |
proxy_buffer |
设置缓存区的数量和大小,Nginx从代理的后端服务器获取的响应信息,会放置到缓存区 |
proxy_busy_buffer_size |
用于设置系统很忙是可以使用的proxy_buffer大小,官方推荐大小为proxy_buffers*2 |
proxy_temp_file_write_size |
指定proxy缓冲临时文件的大小 |
相关重要参数
相关重要参数 |
参数说明 |
proxy_psss http://server_pools |
通过proxy_pass功能把用户的请求转向到反向代理定义的upstream服务器池 |
proxy_set_header Host $host |
在代理后端服务器发送的http请求头中加入host字段信息,用于后端服务器配置有多个虚拟主机主机是可以识别是那个虚拟主机。这是节点服务器多虚拟主机时的关键配置 |
proxy_set_header X-Forwarded-For $remote_addr;
|
在反向代理服务器发送http请求头加入X-Forwarded-For字段信息,用于后端服务程序、日志等接受记录真实的IP,而不是代理服务器的IP这是反向代理时,节点服务器获取用户真实IP的必要功能配置 后面服务器,记录日志格式,main |
根据URL中的目录地址实现代理转发说明
1.1.1 案例背景:通过Nginx实现动静分离,即通过Nginx反向代理规则实现让动态资源和静态资源及其他业务分别由不同的服务器解析,已解决网站性能、安全、用户体验等重要问题。
下面图适合网站前端只使用同一个域名提供服务的场景,例如,用户访问的域名是www.etiantian.org,然后,当用户请求求www.etiantian.org/upload/xx地址时,代理会分配请求到上传服务器池处理数据;当用户请求
www.etiantian.org/static/xx地址时,代理会分配请求到静态服务器池请求数据;当用户请求
www.etiantian.org/xx地址时候,即不包含上述指定的目录地址路径时,代理会分配请求到默认的动态服务器池请求数据(注意:上面的xx表示任意路径)
1.1 案例配置实战
当用户请求www.etiantian.org/upload/xx地址时,实现由upload上传服务器池处理请求。
当用户请求www.etiantian.org/static/xx地址时,实现由静态服务器池处理请求
除此之外,对于其他访问请求,全部默认的动态服务器池处理请求
负载均衡器上实现/配置:
用户请求的URI |
负责处理的服务器 |
主机名 |
站点目录 |
功能 |
/upload |
10.0.0.8:80 |
web01 |
html/www/upload |
upload服务器 |
/static |
10.0.0.7:80 |
web02 |
html/www/static |
static静态服务器 |
/ |
10.0.0.9:80 |
web03 |
html/bbs |
默认 |
www.etiantian.org/bingbiang.html |
#测试proxy_set_header X_Forwarded_For 记录客户端IP地址
#让web服务器员记录客户端IP
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- upstream server_pools {
- server 10.0.0.7:80 weight=4 max_fails=3 fail_timeout=30s;
- server 10.0.0.8:80 weight=4 max_fails=3 fail_timeout=30s;
- server 10.0.0.9:80 weight=4 max_fails=3 fail_timeout=30s;
- }
- server {
- listen 80;
- server_name www.etiantian.org;
- location / {
- proxy_pass http://server_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- }
- server {
- listen 80;
- server_name bbs.etiantian.org;
- location / {
- proxy_pass http://server_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- }
- }
- #在web服务器服务员监测日志信息
- #[root@web01 ~]# tailf /application/nginx/logs/access.log
- #测试结果
- #10.0.0.5 - - [25/May/2017:16:55:14 +0800] "GET /bingbing.html HTTP/1.0" 200 14 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36" "10.0.0.253"
- #重启Nginx,语法检测。
- #[root@lb01 conf]# /application/nginx/sbin/nginx -t
- #nginx: the configuration file /application/nginx-1.10.2/conf/nginx.conf syntax is ok
- #nginx: configuration file /application/nginx-1.10.2/conf/nginx.conf test is successful
- #[root@lb01 conf]# /application/nginx/sbin/nginx -s reload
- ###根据用户请求url目录(URI )进行转发 用户请求
- 第一个里程碑
- #配置文件
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- upstream upload_pools {
- server 10.0.0.8:80;
- }
- upstream static_pools {
- server 10.0.0.7:80;
- }
- upstream default_pools {
- server 10.0.0.9:80;
- }
- server {
- listen 80;
- server_name www.etiantian.org;
- location /upload {
- proxy_pass http://upload_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- location /static {
- proxy_pass http://static_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- location / {
- proxy_pass http://default_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- }
- }
- ########nginx 给予uri 目录的转发
- #创建环境
- ##web01
- mkdir -p /application/nginx/html/www/upload
- echo "web01 upload" >/application/nginx/html/www/upload/bingbing.html
- ##web02
- mkdir -p /application/nginx/html/www/static
- echo "web02 static" >/application/nginx/html/www/static/bingbing.html
- ##web03
- echo "web03 default" >/application/nginx/html/www/bingbing.html
- ##测试结果
- #[root@lb01 conf]# curl 10.0.0.5/bingbing.html
- #web03 default
- #[root@lb01 conf]# curl 10.0.0.5/static/bingbing.html
- #web02 static
- #[root@lb01 conf]# curl 10.0.0.5/upload/bingbing.html
- #web01 upload
#让web服务器员记录客户端IP
##根据用户请求的url目录(URI)进行转发 用户的请求总的
- ####第一个里程碑-规划 分类
- /upload 10.0.0.8:80 upload服务器
- /static 10.0.0.7:80 static静态服务器
- / 10.0.0.9:80 默认
- ####第二个里程碑-创建澡堂子
- upstream upload_pools {
- server 10.0.0.8:80;
- }
- upstream static_pools {
- server 10.0.0.7:80;
- }
- upstream default_pools {
- server 10.0.0.9:80;
- }
- ##第三个里程碑-什么时候去某一个澡堂子(条件)
- location ====== 专门用来匹配 判断 uri if ($uri ~ xxxx)
- location /static/ {
- proxy_pass http://static_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- #将符合upload的请求交给上传服务器池upload_pools,配置如下:
- location /upload/ {
- proxy_pass http://upload_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- #不符合上述规则的请求,默认全部交给动态服务器池default_pools,配置如下:
- location / {
- proxy_pass http://default_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- ###第四个里程碑-配置lb负载均衡
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- upstream upload_pools {
- server 10.0.0.8:80;
- }
- upstream static_pools {
- server 10.0.0.7:80;
- }
- upstream default_pools {
- server 10.0.0.9:80;
- }
- server {
- listen 80;
- server_name www.etiantian.org;
- location /static/ {
- proxy_pass http://static_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- location /upload/ {
- proxy_pass http://upload_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- location / {
- proxy_pass http://default_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- access_log logs/access_www.log main;
- }
- }
- ###第五个里程碑-创建环境
- www.etiantian.org/bingbing.html
- www.etiantian.org/upload/bingbing.html
- www.etiantian.org/static/bingbing.html
- ##web01
- mkdir -p /application/nginx/html/www/upload
- echo "web01 upload" >/application/nginx/html/www/upload/bingbing.html
- ##web02
- mkdir -p /application/nginx/html/www/static
- echo "web02 static" >/application/nginx/html/www/static/bingbing.html
- ##web03
- echo "web03 default" >/application/nginx/html/www/bingbing.html
- ###第五个里程碑-进行测试
- #[root@lb01 conf]# curl www.etiantian.org/bingbing.html
- #web03 default
- #[root@lb01 conf]# curl www.etiantian.org/static/bingbing.html
- #web02 static
- #[root@lb01 conf]# curl www.etiantian.org/upload/bingbing.html
- #web01 upload
- ####下面三条要解析否则会报404
- curl www.etiantian.org/bingbing.html
- curl www.etiantian.org/static/bingbing.html
- curl www.etiantian.org/upload/bingbing.html
- curl 10.0.0.5/bingbing.html
- curl 10.0.0.5/static/bingbing.html
- curl 10.0.0.5/upload/bingbing.html
##根据用户请求的url目录(URI)进行转发 用户的请求总的
根据用户客户端的设备(user_agent)转发实践
###nginx.conf lb01 基于 用户的客户端浏览器
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- upstream upload_pools {
- server 10.0.0.8:80;
- }
- upstream static_pools {
- server 10.0.0.7:80;
- }
- upstream default_pools {
- server 10.0.0.9:80;
- }
- server {
- listen 80;
- server_name www.etiantian.org;
- location / {
- if ($http_user_agent ~* "MSIE")
- {
- proxy_pass http://static_pools;
- }
- if ($http_user_agent ~* "Chrome")
- {
- proxy_pass http://upload_pools;
- }
- proxy_pass http://default_pools;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- }
- }
- }
- ##因为10.0.0.5下没有动态或静态的东西
- [root@lb01 conf]# curl 10.0.0.5/bingbing.html
- web03 default
- [root@lb01 conf]# curl 10.0.0.5/static/bingbing.html
- <html>
- <head><title>404 Not Found</title></head>
- <body bgcolor="white">
- <center><h1>404 Not Found</h1></center>
- <hr><center>nginx/1.10.2</center>
- </body>
- </html>
- [root@lb01 conf]# curl 10.0.0.5/upload/bingbing.html
- <html>
- <head><title>404 Not Found</title></head>
- <body bgcolor="white">
- <center><h1>404 Not Found</h1></center>
- <hr><center>nginx/1.10.2</center>
- </body>
- </html>
- #加A + 参数指定浏览器名字
- [root@lb01 conf]# curl -A chrome 10.0.0.5/upload/bingbing.html
- web01 upload
- [root@lb01 conf]# curl 10.0.0.5/bingbing.html
- web03 default
- [root@lb01 conf]# curl -A msie 10.0.0.5/static/bingbing.html
- web02 static
- [root@lb01 conf]# ####访问一个目录 nginx 默认找的文件是 index.html index.htm
- [root@lb01 conf]# #####如果这些文件不存在 nginx报错 403
- [root@lb01 conf]# curl -A chrome 10.0.0.5/upload/oldboy.txt
- <html>
- <head><title>404 Not Found</title></head>
- <body bgcolor="white">
- <center><h1>404 Not Found</h1></center>
- <hr><center>nginx/1.10.2</center>
- </body>
- </html>
- ##################
- ###报404
- [root@lb01 conf]# ####1.10.0.0.5 访问的反向代理 lb01
- [root@lb01 conf]# ####2.10.0.0.5 默认访问第一个虚拟主机 server
- [root@lb01 conf]# ####3.查看对应的条件 uri 目录
- [root@lb01 conf]# # if ($http_user_agent ~* "MSIE")
- [root@lb01 conf]# #
- [root@lb01 conf]# # {
- [root@lb01 conf]# # proxy_pass http://static_pools;
- [root@lb01 conf]# # }
- [root@lb01 conf]# # if ($http_user_agent ~* "Chrome")
- [root@lb01 conf]# #
- [root@lb01 conf]# # {
- [root@lb01 conf]# # proxy_pass http://upload_pools;
- [root@lb01 conf]# # }
- [root@lb01 conf]# #proxy_pass http://default_pools;
- [root@lb01 conf]# ####4.最后找到的是 默认的池塘 里面没有 upload 目录
- [root@lb01 conf]# ####5. 没有这个目录 404 找不到
- [root@lb01 conf]# curl 10.0.0.5/upload/
- <html>
- <head><title>404 Not Found</title></head>
- <body bgcolor="white">
- <center><h1>404 Not Found</h1></center>
- <hr><center>nginx/1.10.2</center>
- </body>
- </html>
- ############403错误
- [root@lb01 conf]# curl -A msie 10.0.0.5/static/
- <html>
- <head><title>403 Forbidden</title></head>
- <body bgcolor="white">
- <center><h1>403 Forbidden</h1></center>
- <hr><center>nginx/1.10.2</center>
- </body>
- </html>
- [root@lb01 conf]# ####1.lb01
- [root@lb01 conf]# ####2.匹配的是第一个虚拟主机 10.0.0.5 www.etiantian.org
- [root@lb01 conf]# ####3.进入location
- [root@lb01 conf]# ####4.进入location /
- [root@lb01 conf]# ####5.判断
- [root@lb01 conf]# ####-A 装作是msie
- [root@lb01 conf]# ####7.10.0.0.7 这个机器上面 有/static 目录
- [root@lb01 conf]# ####8.10.0.0.5/static/ ===== 10.0.0.5/static/index.html
- [root@lb01 conf]# ####9.找首页文件 但是 首页文件不存在就显示403 默认去找index.html
- [root@lb01 conf]#
- [root@lb01 conf]# ####10.找不到就汇报403 错误 。
- ##1.浏览器缓存 ctrl+F5
- ##2.域名没有解析
- ##3.修改了配置文件,没重启 配置文件没生效
- [root@lb01 conf]# cat nginx.conf
- ####lb01负载均衡
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- sendfile on;
- keepalive_timeout 65;
- default_type application/octet-stream;
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- upstream uplaod_pools {
- server 10.0.0.8:80;
- }
- upstream static_pools {
- server 10.0.0.7:80;
- }
- upstream default_pools {
- server 10.0.0.9:80;
- }
- server {
- listen 80;
- server_name www.etiantian.org;
- location / {
- if ($http_user_agent ~* "MSIE")
- {
- proxy_pass http://static_pools;
- }
- if ($http_user_agent ~* "Chrome")
- {
- proxy_pass http://uplaod_pools;
- }
- proxy_pass http://default_pools;
- }
- access_log logs/access_www.log main;
- }
- }
###nginx.conf lb01 基于 用户的客户端浏览器
http proxy模块参数的更多相关文章
- nginx反向代理proxy模块相关参数
http_proxy_module Proxy_pass proxy_pass指令属于ngx_http_proxy_module模块,此模块可以将请求转发到另一台服务器:官方说明:http://ngi ...
- nginx的proxy模块详解以及参数
文章来源 运维公会:nginx的proxy模块详解以及参数 使用nginx配置代理的时候,肯定是要用到http_proxy模块.这个模块也是在安装nginx的时候默认安装.它的作用就是将请求转发到相应 ...
- 【web安全】第五弹:burpsuite proxy模块的一些理解
作为一只小小小白的安全新手,只会简单的用sqlmap扫扫网站,用burpsuite的proxy模块拦截一些请求.最近又对proxy有点儿小理解,记录之. 1. 查看sqlmap注入的语句以及HTTP ...
- Nginx配置之location模块和proxy模块
1.location指令的用法介绍 Location主要用来匹配url,如:http://www.beyond.com/nice,在这里对于location来说www.beyond.com是域名,/n ...
- insmod module_param 模块参数
模块参数 引导模块时,可以向它传递参数.要使用模块参数加载模块,这样写: insmod module.ko [param1=value param2=value ...] 为了使用这些参数的值,要在模 ...
- Verilog 模块参数重定义(转)
Verilog重载模块参数: 当一个模块引用另外一个模块时,高层模块可以改变低层模块用parameter定义的参数值,改变低层模块的参数值可采用以下两种方式: 1)defparam 重定义参数语法:d ...
- 模块参数,系统调用,字符设备编程重要数据结构,设备号的申请与注册,关于cdev的API
1.模块参数 应用编程: int main(int argc, char *argv[]) { } ./a.out xxx yyy zzz ...
- Linux设备驱动程序 之 模块参数
模块支持参数的方法 内核允许驱动程序指定参数,这些参数可在运行insmod或者modprobe命令装载模块时赋值,modprobe还可以从它的配置文件(/etc/modporb.conf)中读取参数值 ...
- linux模块参数
驱动需要知道的几个参数因不同的系统而不同. 从使用的设备号( 如我们在下一章见到的 ) 到驱动应当任何操作的几个方面. 例如, SCSI 适配器的驱动常常有选项控制标记命令队列 的使用, IDE 驱动 ...
随机推荐
- bootstrap-实现loading效果
可以使用bootstrap的模态框(modal.js),使用它我们可以做出loading效果. html <!-- loading --> <div class="moda ...
- HTTPS之acme.sh申请证书
1.关于let's encrypt和acme.sh的简介 1.1 let's encrypt Let's Encrypt是一个于2015年三季度推出的数字证书认证机构,旨在以自动化流程消除手动创建和安 ...
- [Java] Windows/Linux路径不同时,统一war的最简办法
作者: zyl910 一.缘由 在项目开发时,因为运行环境的不同,导致有时得分别为不同的环境,切换配置参数打不同war包.但手工切换配置文件的话,不仅费时费力,而且容易出错. 有些打包工具支持配置切换 ...
- Effective Java 第三版—— 85. 其他替代方式优于Java本身序列化
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- 【C语言天天练(三)】typedef具体解释
引言: typedef能够看作type define的缩写,顾名思义就是类型定义,也就是说它仅仅是给已有的类型又一次定义了一个方便使用的别名.并没有产生新的数据类型. typedef与define的不 ...
- Xshell设置密钥登录CentOS6.5_64位(文字命令版)
1.新建/root/.ssh目录 mkdir /root/.ssh 2.创建authorized_keys文件 vi /root/.ssh/authorized_keys 3.复制公钥内容保存 :wq ...
- The thumbprint of same asymmetric key is not same in 'SQL Server Connector for Microsoft Azure Key Vault' 1.0.4.0 and 'SQL Server Connector for Microsoft Azure Key
https://support.microsoft.com/en-us/help/4470999/db-backup-problems-to-sql-server-connector-for-azur ...
- Django Rest Framework(认证、权限、限制访问频率)
阅读原文Django Rest Framework(认证.权限.限制访问频率) django_rest_framework doc django_redis cache doc
- Mongodb常用增删改查语法
1,新增 新增有两种方式 var Tank = mongoose.model('Tank', yourSchema); var small = new Tank({ size: 'small' }); ...
- vim简单的移动光标
vim学习简单的光标移动 ==> 移动到行首 $ ==> 移动到行尾 ^ ==> 移动到本行第一个不是blank的位置 g_ ==> 移动到本行最后一个不是blank的位置^Z ...