不同文件后缀返回不同 Content-Type 并修改响应内容追加脚本123456789101112131415161718192021222324252627282930server { listen xxx; server_name xx; location / { proxy_pass http://xxx; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; if ($request_uri ~* .*/raw/.*\.html$) { add_header Content-Type 'text/html; charset=utf-8'; } sub_filter '</body>' '<script src="xxx.js"></script></body>'; sub_filter_once on; if ($request_uri ~* .*/raw/.*\.css$) { add_header Content-Type 'text/css; charset=utf-8'; } if ($request_uri ~* .*/raw/.*\.js$) { add_header Content-Type 'application/x-javascript'; } if ($request_uri ~* .*/raw/.*\.svg$) { add_header Content-Type 'image/svg+xml'; } }}