nginx proxy_pass 和 proxy_redirect
proxy_pass:充当代理服务器,转发请求
proxy_redirect:修改301或者302转发过程中的Location。默认值为proxy_redirect default。
例:
location / {
proxy_pass http://192.168.8.46:8080/; #/结尾
#proxy_redirect default #此为默认值,加不加都一样。
}
这样代理到其它机器的8080端口,访问的时候都没问题,
Location: http://192.168.8.46/haha4/,浏览器的url地址栏也是http://192.168.8.46/haha4/
若:
location / {
proxy_pass http://192.168.8.46:8080;#去掉/
proxy_redirect off #修改默认值default为off
}
如果去掉最后的/以后,curl -I http://192.168.8.46/haha4 访问
Location: http://192.168.8.46:8080/haha4/
浏览器访问显示的地址栏为http://192.168.8.46:8080/haha4/,(如果还是之前的,需要先删缓存)
可以看到,真实的Location地址全部暴露出来的,这个时候就需要使用proxy_redirect修改这个Location
配置如下:
location / {
proxy_pass http://192.168.8.46:8080;
proxy_redirect http://192.168.8.46:8080/haha4/ http://192.168.8.46/haha4/;
}
这样,就能修改Location的地址,Location: http://192.168.8.46/haha4/,在浏览器里也是如此,就不会暴露端口号等信息,
当然,你还可以把Location弄到其它网站上去,例如
proxy_redirect http://192.168.8.46:8080/haha4/ http://www.douban.com/;
然后浏览器就跳过去了。
总结:
一切幕后黑手就是
proxy_pass http://192.168.8.46:8080; 不加/结尾,只要把/加上,proxy_redirect 用默认值就OK了。
nginx proxy_pass 和 proxy_redirect的更多相关文章
- nginx proxy_pass 指令
nginx proxy_pass 指令 文档 Nginx 官方文档 https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pa ...
- nginx proxy_pass
在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理 ...
- nginx proxy_pass 与 rewrite 简记
rewrite syntax: rewrite regex replacement [flag] Default: - Context: server, location, if 如果正则表达式(re ...
- nginx proxy_pass 代理域名
一.描述 1.nginx配置转发的时候使用的是域名,即使用dns服务方便配置和负载.但是nginx默认会进行缓存,当域名对应的服务出问题的时候就会报错,只有默认的缓存时间到了才会再次进行解析,ngin ...
- nginx proxy_pass指令’/’注意事项
1. proxy_pass配置说明 不带/ location /test/ { proxy_pass http://t6:8300; } 带/ location /test/ { proxy_pass ...
- 用反向代理nginx proxy_pass配置解决ie8 ajax请求被拦截问题 ie8用nginx代理实现跨域请求访问 nginx405正向代理request_uri
最近调PC版网站ie8的兼容性,发现所有ajax请求还没到后端服务器就直接ajax error了 ie8发不出ajax请求,断点调试发现ajax全进入了error,提示“No transport” 我 ...
- nginx proxy_pass后的url加不加/的区别
在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走. 下面四种 ...
- NGINX proxy_pass 域名解析问题
前两天发现一个问题,当使用proxy_pass的时候,发现域名对应IP是缓存的,这样一旦VIP变化之后,就会报错,下面就来详细分析一下这个问题. 一.问题说明 location = /test { i ...
- [nginx]proxy_pass&rewrite知识点
While passing request nginx replaces URI part which corresponds to location with one indicated in pr ...
随机推荐
- Paper Reading
Paper Reading_SysML Paper Reading_Computer Architecture Paper Reading_Database Paper Reading_Distrib ...
- JS全选的操作
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 值不能为null.参数名: viewInfo,如何解决
有蓝队网络服务器租用客户反映在一台服务器上使用数据库管理工具时弹出了如下错误 :值不能为null.参数名: viewInfo (Microsoft.SqlServer.Management.SqlSt ...
- IDEA创建maven的web项目时,main文件夹下没有java,resources目录等源文件夹
https://blog.csdn.net/qq_34377273/article/details/83183307
- python 模块发布及使用
将模块(此处名为nester)写好后,与setup.py放入同一个文件夹中: //setup.py from distutils.core import setup setup( name=" ...
- python 字符串 常用方法
name = 'ALLix9' print(name.casefold()) # 大写变成小写 name.lower() # 全变小写 '.isnumeric()) #判断是否是数字:正整数 prin ...
- vue中的:is
is string | Object (组件的选项对象) <div id="app"> <span>这是:is的案例</span> <co ...
- JavaScript自增和自减
一.自增++ 通过自增运算符可以使变量在自身的基础上加一: 对于一个变量自增以后,原变量的值会立即自增一: 自增符号:++ 自增分为两种:1.后++(a++):2.前++(++a): 共同点:a++ ...
- php array_flip()函数 语法
php array_flip()函数 语法 作用:用于反转/交换数组中所有的键名以及它们关联的键值.富瑞联华 语法:array_flip(array); 参数: 参数 描述 array 必需.规定需进 ...
- PHP文件的上传和下载
1.使用PHP的创始人 Rasmus Lerdorf 写的APC扩展模块来实现(http://pecl.php.net/package/apc) APC实现方法: 安装APC,参照官方文档安装,可以使 ...