翼度科技»论坛 云主机 服务器技术 查看内容

nginx中的proxy_redirect的使用案例详解

4

主题

4

帖子

12

积分

新手上路

Rank: 1

积分
12
一 proxy_redirect的作用

proxy_redirect 该指令用来修改被代理服务器返回的响应头中的Location头域和“refresh”头域

二 语法结构
  1. proxy_redirect 旧地址 新地址;
  2. proxy_redirect default;  #默认配置
  3. proxy_redirect off;   #关闭重定向
复制代码
三 案例

如果需要修改从被代理服务器传来的应答头中的"Location"和"Refresh"字段,可以用这个指令设置。
1.假设被代理服务器返回Location字段为: http://localhost:8000/two/some/uri/
这个指令:
  1. proxy_redirect http:
复制代码
  1. //localhost
复制代码
  1. :8000
复制代码
  1. /two/
复制代码
     
  1. http:
复制代码
  1. //frontend/one/
复制代码
  1. ;
复制代码
将Location字段重写为http://frontend/one/some/uri/。
2.在代替的字段中可以不写服务器名:
  1. proxy_redirect http://localhost:8000/two/ /;
复制代码
这样就使用服务器的基本名称和端口,即使它来自非80端口。
3.参数off将在这个字段中禁止所有的proxy_redirect指令
  1. proxy_redirect off;
  2. proxy_redirect default;
  3. proxy_redirect http://localhost:8000/ /; proxy_redirect ; /;1.
复制代码
4.利用proxy_redirect这个指令可以为被代理服务器发出的相对重定向增加主机名:
扩展:nginx proxy_redirect https配置后端http302跳转处理
  1. # HTTPS server
  2.     #
  3.     server {
  4.         listen       443 ssl;
  5.         server_name  localhost;
  6.         charset utf8;
  7.         ssl_certificate      full_chain.pem;
  8.         ssl_certificate_key  private.key;
  9.         ssl_session_cache    shared:SSL:1m;
  10.         ssl_session_timeout  5m;
  11.         ssl_ciphers  HIGH:!aNULL:!MD5;
  12.         ssl_prefer_server_ciphers  on;
  13.         proxy_set_header Host $host;
  14.         proxy_set_header X-Real-IP $remote_addr;
  15.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  16.         proxy_set_header X-Forwarded-Proto $scheme;
  17.         proxy_connect_timeout      10;
  18.         proxy_send_timeout         90;
  19.         proxy_read_timeout         90;
  20.         proxy_redirect http://$host/ https://$host:$server_port/;
  21.         location /mgr/ {
  22.                 proxy_pass http://localhost:8080/mgr/;
  23.         }
  24.     }
复制代码
到此这篇关于nginx中的proxy_redirect的使用的文章就介绍到这了,更多相关nginx proxy_redirect的使用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

来源:https://www.jb51.net/server/322230anf.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具