nginx代理服务响应成功,但没有返回内容
配置如下:
location /assets/sensors/ {
# prelight request
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
# 设置字符集为utf-8
charset utf-8;
# 指定sub_filter规则(将old字符串替换为new字符串)
# sub_filter 'old' 'new';
# 开启sub_filter模块
sub_filter_types text/css text/javascript;
# 目标服务
proxy_pass https://mstatic.cassmall.com/assets/sensors/;
# 传递客户端请求的头信息给目标服务器
proxy_pass_request_headers on;
# 控制是否传递客户端请求的请求体(body)给目标服务器
proxy_pass_request_body on;
# 设置 Host 头字段为客户端请求中的主机名
proxy_set_header Host $host;
# 设置 X-Real-IP 头字段为客户端的真实 IP 地址
proxy_set_header X-Real-IP $remote_addr;
# 用于在代理服务器链路中追踪客户端的真实 IP 地址
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 将客户端和代理服务器之间的协议添加到 X-Forwarded-Proto 头字段
proxy_set_header X-Forwarded-Proto $scheme;
# 指令禁用了自动重定向,以确保代理服务器原样返回目标服务器的响应给客户端
proxy_redirect off;
# 指令将响应的Content-Length头信息设置为空,以确保响应的长度由实际内容决定
proxy_set_header Content-Length "";
# 指令将目标服务器响应的Content-Length头信息保存在X-Original-Content-Length头信息中,以便正确返回给客户端
proxy_set_header X-Original-Content-Length $upstream_http_content_length;
# 设置延迟
set $delay 0.3;
echo_sleep $delay;
}
把最后一行
echo_sleep
去掉就可以了。因为这算是同时注册了两个content handler,echo和proxy_pass,看上去echo配置排在proxy_pass后面,所以只有echo模块生效了。
在github上看到了一个一样问题的issue
https://github.com/openresty/echo-nginx-module/issues/5
===