V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
wgit
V2EX  ›  NGINX

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

  •  1
     
  •   wgit · 2022-09-10 21:00:15 +08:00 · 1892 次点击
    这是一个创建于 565 天前的主题,其中的信息可能已经有所发展或是发生改变。

    配置文件

        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 的时候内容倒是没问题

    6 条回复    2022-09-11 12:02:34 +08:00
    eason1874
        1
    eason1874  
       2022-09-10 21:17:00 +08:00   ❤️ 1
    sub_filter 只替换 body 不替换 header ,你得用 njs 或者 ngx_lua 模块去替换 header
    muhuan
        2
    muhuan  
       2022-09-10 21:30:55 +08:00   ❤️ 1
    mmdsun
        3
    mmdsun  
       2022-09-11 00:21:05 +08:00   ❤️ 1
    之前也遇到替换网页内容 /头的需求,用 nginx + sub_filter 折腾太麻烦了。
    随便一个应用网关就能做的的事情 比如 zuul \ spring gateway 修改请求响应非常容易。
    wgit
        4
    wgit  
    OP
       2022-09-11 00:27:00 +08:00
    @mmdsun 前面试下了二楼发的模块,很方便
    ptyfork
        5
    ptyfork  
       2022-09-11 04:36:08 +08:00
    Caddy + replace 插件
    dusu
        6
    dusu  
       2022-09-11 12:02:34 +08:00 via iPhone
    proxy_hide_header
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5253 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 09:24 · PVG 17:24 · LAX 02:24 · JFK 05:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.