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 驱动 ...
随机推荐
- c++中transform()函数和find()函数的使用方法。
1.transform函数的使用 transform在指定的范围内应用于给定的操作,并将结果存储在指定的另一个范围内.transform函数包含在<algorithm>头文件中. 以下是s ...
- VUE温习:style层次分析
一.vue样式style层次分析 1.样式可以在main.js.模块js文件.组件style.组件script标签内,index.html文件内引入,不同位置引入的样式有什么关系. 2.总结: (1) ...
- CentOS7本地安装MySQL5.7
操作系统:3.10.0-514.el7.x86_64 安装包:mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 1:检查是否安装了 libaio(centos7默认 ...
- HDU 1022.Train Problem I【栈的应用】【8月19】
Train Problem I Problem Description As the new term comes, the Ignatius Train Station is very busy n ...
- android Glide简单使用
版权声明:大家可以转载,请写明转载申明 https://blog.csdn.net/bzlj2912009596/article/details/81702367 今天,简单讲讲Android里Gli ...
- ExpandableListView使用(三)-ScrollView嵌套ExpandableListView,列表显示不全
前言 ScrollView嵌套ExpandableListView会出现ExpandableListView列表显示不全,目前比较好的方法是复写ExpandableListView,重写里面的onMe ...
- BizTalk RosettaNet 配置导入与导出
更多内容请查看:BizTalk动手实验系列目录 BizTalk 开发系列 BizTalk 培训/项目开发/技术支持请联系:Email:cbcye ...
- Myeclipse安装、配置、测试
Myeclipse安装.配置.测试(win7_64bit) 目录 1.概述 2.本文用到的工具 3.安装与激活 4.JavaSE开发测试(确保JDK已正确安装) 5.JavaEE开发测试(确保服务器和 ...
- crontab 选择编辑器 select-editor
用root第一次运行 crontab -e 会出现如题的错误,解决方法如下: 1.select-editor 选择编辑器,我选的vim.basic. 2.crontab -e 进入编辑器编辑. 推荐第 ...
- ubuntu 下无损扩展分区
命令扩展: http://www.cnblogs.com/greatfish/p/7347945.html http://www.cnblogs.com/wangxingggg/articles/68 ...