最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

proxy

互联网 admin 22浏览 0评论

proxy

目录

1、作用:

2、语法:

2.1、替换的例子 一:

2.2、替换的例子 二:

3、容易用到的场景:

3.1、场景前提

3.2、实例对比实验

4、部分特性:


1、作用:

1、用来修改 被代理服务器(真实服务器) 返回的响应头中的 location 头域(location标识着客户端访问的地址) 和 refresh头域。 2、利用proxy_redirect这个指令可以为被代理服务器发出的相对重定向增加主机名。

2、语法:

proxy_redirect    redirect(旧地址)  replacement(新地址); proxy_redirect    default;     #默认设置 proxy_redirect    off;           #关闭重定向

2.1、替换的例子 一:

假设 代理 服务器返回 Location字段为: http://localhost:8000/two/some/uri/ proxy_redirect      http://localhost:8000/two/    http://frontend/one/; 将Location字段重写为http://frontend/one/some/uri/

2.2、替换的例子 二:

在代替的新的字段中可以不写服务器名, 这样就使用服务器的基本名称和端口,即使它来自非80端口。 proxy_redirect  http://$host:8080/    /  ;    # 把客户端访问端口跳转回默认端口,这里可能是80         通常需要这么做的机会很少。

3、容易用到的场景:

假设请求链接是  结果会被301重定向到请求的链接为  :8080/aming/  

3.1、场景前提

但实现这种“容易失误”的重定向有 几个前提 才会发生: 1、需要 locatin 是 /  而不是匹配更复杂;proxy_pass 不能加uri,且最后不能 / 结尾 (  注:如果proxy_pass 最后加 / 的话,是不会发生这种情况的,所以还是习惯加 / 的好 ) 2、访问的uri必须是真实存在的目录,比如这里的 aming 目录是必须存在的 3、访问的URL不能以 / 结尾 。只能是    而不能是 /

3.2、实例对比实验

例: #假如代理服务器  还没加 proxy_redirect server { listen  80; server_name  www.test.com; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header host $host; proxy_set_header X-Real-IP  $remote_addr; proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for; } } 真实的有 /data/wwwroot/test.com/aming 目录,目录下有 index.html文件,文件内写着如下 curl -x192.168.133.140:80  www.test.com/aming/    结尾有 /    访问到  /data/wwwroot/test.com/aming/index.html   ,正常 curl -x192.168.133.140:80  www.test.com/aming 结尾不带 /   访问到 www.test.com :8080/aming/          ,发生错误 因为客户访问到的代理服务器,没开8080端口,客户端这样访问会导致访问失败。 在代理上记录日志 在后端服务器记录日志 日志 添加上  端口记录字段 curl -x192.168.133.140:80  www.test.com/aming/ 时,都是正确的 代理服务器日志显示被访问的是80端口 被代理服务器显示被访问的是8080端口 curl -x192.168.133.140:80  www.test.com/aming  不带 /  时,会产生301重定向问题 这里可以看到客户端请求的响应头  Location 显示的是 8080 端口,证明客户端的请求被改为访问8080端口了 代理服务器日志显示被访问的是80端口,重定向了一次被访问端口变成了8080。 这可是记录的客户端的访问,客户端访问8080在代理服务器上是没有对应的监听的,因此会发生了301重定向错误。  被代理服务器显示访问的是8080端口,也重定向了一次 所以这里需要加上 proxy_redirect ,把8080重定向回来80。 server { listen  80; server_name  www.test.com; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header host $host; proxy_set_header X-Real-IP  $remote_addr; proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for; proxy_redirect  http://$host:8080/    /;           # 把客户端的请求跳转回80         } } 客户端访问成功,代理服务器 Location 响应头显示:客户的请求不再重定向到8080端口。

4、部分特性:

redirect  跳转页面,是服务端返回新的 url 地址, 浏览器二次发出 url 请求 , 属于一次 全新 的 http 请求,无法携带上一次请求的参数。

proxy

目录

1、作用:

2、语法:

2.1、替换的例子 一:

2.2、替换的例子 二:

3、容易用到的场景:

3.1、场景前提

3.2、实例对比实验

4、部分特性:


1、作用:

1、用来修改 被代理服务器(真实服务器) 返回的响应头中的 location 头域(location标识着客户端访问的地址) 和 refresh头域。 2、利用proxy_redirect这个指令可以为被代理服务器发出的相对重定向增加主机名。

2、语法:

proxy_redirect    redirect(旧地址)  replacement(新地址); proxy_redirect    default;     #默认设置 proxy_redirect    off;           #关闭重定向

2.1、替换的例子 一:

假设 代理 服务器返回 Location字段为: http://localhost:8000/two/some/uri/ proxy_redirect      http://localhost:8000/two/    http://frontend/one/; 将Location字段重写为http://frontend/one/some/uri/

2.2、替换的例子 二:

在代替的新的字段中可以不写服务器名, 这样就使用服务器的基本名称和端口,即使它来自非80端口。 proxy_redirect  http://$host:8080/    /  ;    # 把客户端访问端口跳转回默认端口,这里可能是80         通常需要这么做的机会很少。

3、容易用到的场景:

假设请求链接是  结果会被301重定向到请求的链接为  :8080/aming/  

3.1、场景前提

但实现这种“容易失误”的重定向有 几个前提 才会发生: 1、需要 locatin 是 /  而不是匹配更复杂;proxy_pass 不能加uri,且最后不能 / 结尾 (  注:如果proxy_pass 最后加 / 的话,是不会发生这种情况的,所以还是习惯加 / 的好 ) 2、访问的uri必须是真实存在的目录,比如这里的 aming 目录是必须存在的 3、访问的URL不能以 / 结尾 。只能是    而不能是 /

3.2、实例对比实验

例: #假如代理服务器  还没加 proxy_redirect server { listen  80; server_name  www.test.com; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header host $host; proxy_set_header X-Real-IP  $remote_addr; proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for; } } 真实的有 /data/wwwroot/test.com/aming 目录,目录下有 index.html文件,文件内写着如下 curl -x192.168.133.140:80  www.test.com/aming/    结尾有 /    访问到  /data/wwwroot/test.com/aming/index.html   ,正常 curl -x192.168.133.140:80  www.test.com/aming 结尾不带 /   访问到 www.test.com :8080/aming/          ,发生错误 因为客户访问到的代理服务器,没开8080端口,客户端这样访问会导致访问失败。 在代理上记录日志 在后端服务器记录日志 日志 添加上  端口记录字段 curl -x192.168.133.140:80  www.test.com/aming/ 时,都是正确的 代理服务器日志显示被访问的是80端口 被代理服务器显示被访问的是8080端口 curl -x192.168.133.140:80  www.test.com/aming  不带 /  时,会产生301重定向问题 这里可以看到客户端请求的响应头  Location 显示的是 8080 端口,证明客户端的请求被改为访问8080端口了 代理服务器日志显示被访问的是80端口,重定向了一次被访问端口变成了8080。 这可是记录的客户端的访问,客户端访问8080在代理服务器上是没有对应的监听的,因此会发生了301重定向错误。  被代理服务器显示访问的是8080端口,也重定向了一次 所以这里需要加上 proxy_redirect ,把8080重定向回来80。 server { listen  80; server_name  www.test.com; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header host $host; proxy_set_header X-Real-IP  $remote_addr; proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for; proxy_redirect  http://$host:8080/    /;           # 把客户端的请求跳转回80         } } 客户端访问成功,代理服务器 Location 响应头显示:客户的请求不再重定向到8080端口。

4、部分特性:

redirect  跳转页面,是服务端返回新的 url 地址, 浏览器二次发出 url 请求 , 属于一次 全新 的 http 请求,无法携带上一次请求的参数。
Error[2]: Trying to access array offset on value of type int, File: /www/wwwroot/www.usbmi.com/xiunophp/xiunophp.min.php, Line: 54
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 1095, humandate(1738337078)
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 662, well_thread_format(array(26))
File: /www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm, Line: 249, well_thread_find_asc(array(4) , 4)
File: /www/wwwroot/www.usbmi.com/tmp/route_read.php, Line: 204, include(/www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm)
File: /www/wwwroot/www.usbmi.com/tmp/index.inc.php, Line: 129, include(/www/wwwroot/www.usbmi.com/tmp/route_read.php)
File: /www/wwwroot/www.usbmi.com/index.php, Line: 29, include(/www/wwwroot/www.usbmi.com/tmp/index.inc.php)
Error[2]: Trying to access array offset on value of type int, File: /www/wwwroot/www.usbmi.com/xiunophp/xiunophp.min.php, Line: 54
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 1096, humandate(1738337078)
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 662, well_thread_format(array(27))
File: /www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm, Line: 249, well_thread_find_asc(array(4) , 4)
File: /www/wwwroot/www.usbmi.com/tmp/route_read.php, Line: 204, include(/www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm)
File: /www/wwwroot/www.usbmi.com/tmp/index.inc.php, Line: 129, include(/www/wwwroot/www.usbmi.com/tmp/route_read.php)
File: /www/wwwroot/www.usbmi.com/index.php, Line: 29, include(/www/wwwroot/www.usbmi.com/tmp/index.inc.php)
Error[2]: Trying to access array offset on value of type int, File: /www/wwwroot/www.usbmi.com/xiunophp/xiunophp.min.php, Line: 54
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 1095, humandate(1741226508)
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 662, well_thread_format(array(26))
File: /www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm, Line: 249, well_thread_find_asc(array(4) , 4)
File: /www/wwwroot/www.usbmi.com/tmp/route_read.php, Line: 204, include(/www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm)
File: /www/wwwroot/www.usbmi.com/tmp/index.inc.php, Line: 129, include(/www/wwwroot/www.usbmi.com/tmp/route_read.php)
File: /www/wwwroot/www.usbmi.com/index.php, Line: 29, include(/www/wwwroot/www.usbmi.com/tmp/index.inc.php)
Error[2]: Trying to access array offset on value of type int, File: /www/wwwroot/www.usbmi.com/xiunophp/xiunophp.min.php, Line: 54
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 1096, humandate(1741226508)
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 662, well_thread_format(array(27))
File: /www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm, Line: 249, well_thread_find_asc(array(4) , 4)
File: /www/wwwroot/www.usbmi.com/tmp/route_read.php, Line: 204, include(/www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm)
File: /www/wwwroot/www.usbmi.com/tmp/index.inc.php, Line: 129, include(/www/wwwroot/www.usbmi.com/tmp/route_read.php)
File: /www/wwwroot/www.usbmi.com/index.php, Line: 29, include(/www/wwwroot/www.usbmi.com/tmp/index.inc.php)
Error[2]: Trying to access array offset on value of type int, File: /www/wwwroot/www.usbmi.com/xiunophp/xiunophp.min.php, Line: 54
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 1095, humandate(1742327549)
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 662, well_thread_format(array(26))
File: /www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm, Line: 249, well_thread_find_asc(array(4) , 4)
File: /www/wwwroot/www.usbmi.com/tmp/route_read.php, Line: 204, include(/www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm)
File: /www/wwwroot/www.usbmi.com/tmp/index.inc.php, Line: 129, include(/www/wwwroot/www.usbmi.com/tmp/route_read.php)
File: /www/wwwroot/www.usbmi.com/index.php, Line: 29, include(/www/wwwroot/www.usbmi.com/tmp/index.inc.php)
Error[2]: Trying to access array offset on value of type int, File: /www/wwwroot/www.usbmi.com/xiunophp/xiunophp.min.php, Line: 54
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 1096, humandate(1742327549)
File: /www/wwwroot/www.usbmi.com/tmp/model_thread.func.php, Line: 662, well_thread_format(array(27))
File: /www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm, Line: 249, well_thread_find_asc(array(4) , 4)
File: /www/wwwroot/www.usbmi.com/tmp/route_read.php, Line: 204, include(/www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm)
File: /www/wwwroot/www.usbmi.com/tmp/index.inc.php, Line: 129, include(/www/wwwroot/www.usbmi.com/tmp/route_read.php)
File: /www/wwwroot/www.usbmi.com/index.php, Line: 29, include(/www/wwwroot/www.usbmi.com/tmp/index.inc.php)
发布评论

评论列表 (0)

  1. 暂无评论