nginx 反代 响应头未被替换 返回内容正常

2022-09-10 21:00:15 +08:00
 wgit

配置文件

    proxy_set_header Accept-Encoding "";
	sub_filter "a.aa" "c.cc";
    sub_filter_last_modified on;
    sub_filter_types * ;
    sub_filter_once off;

请求头

Accept
	image/avif,image/webp,*/*
Accept-Encoding
	gzip, deflate, br
Accept-Language
	zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Cache-Control
	no-cache
Connection
	keep-alive
Cookie

Host
	c.cc
Pragma
	no-cache
Referer
	https://c.cc/1.html
Sec-Fetch-Dest
	image
Sec-Fetch-Mode
	no-cors
Sec-Fetch-Site
	same-origin
TE
	trailers
User-Agent

响应头

cache-control
	no-cache
content-length
	0
content-type
	text/html; charset=UTF-8
date
	Sat, 10 Sep 2022 12:43:42 GMT
link
	<https://a.aa/wp-json/>; rel="https://api.w.org/"
location
	https://c.cc/wp-includes/images/w-logo-blue-white-bg.png
server
	nginx
strict-transport-security
	max-age=31536000; includeSubdomains;
X-Firefox-Spdy
	h2
x-redirect-by
	WordPress

网页源代码的返回内容都是正常的 但响应头里面有个 link 会暴露源站地址

如果请求 https://c.cc/favicon.ico 第一次响应是 302 也会携带这个 link 302 后再次返回状态码 200 的时候内容倒是没问题

1941 次点击
所在节点    NGINX
6 条回复
eason1874
2022-09-10 21:17:00 +08:00
sub_filter 只替换 body 不替换 header ,你得用 njs 或者 ngx_lua 模块去替换 header
muhuan
2022-09-10 21:30:55 +08:00
mmdsun
2022-09-11 00:21:05 +08:00
之前也遇到替换网页内容 /头的需求,用 nginx + sub_filter 折腾太麻烦了。
随便一个应用网关就能做的的事情 比如 zuul \ spring gateway 修改请求响应非常容易。
wgit
2022-09-11 00:27:00 +08:00
@mmdsun 前面试下了二楼发的模块,很方便
ptyfork
2022-09-11 04:36:08 +08:00
Caddy + replace 插件
dusu
2022-09-11 12:02:34 +08:00
proxy_hide_header

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/879176

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX