nginx使用中碰到的问题

做amp服务时,各种请求通过nginx打到resin服务器上,有个接口是抓取woff字体

woff tff字体获取后,提示如下错误,

Failed to decode downloaded font
比如Failed to decode downloaded font: http://amp.sogoucdn.com/amp/r/twocents.lifehacker.com//f.kinja-static.com/a…ets/fonts/elizabeth-serif/elizabethserif-lightitalic-webfont.woff?09162015
amp:1 OTS parsing error: file less than 4 bytes
 
因为要用到byte[] 所以所有的编码都走的iso-8859-1,参见 http://www.tuicool.com/articles/I7Z3If
首先对自己接口获取的内容与原来接口获取的内容进行比对,发现没有不同
然后,通过debug发现,单独访问该接口可以进入requestmapping,而同一个页面中会请求多次该接口,则不会进入requestmapping接口
加入nginx日志log_format,如下

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for '
'"$upstream_addr" "$upstream_status" "$upstream_response_time" "$request_time"';

打印出来的内容证明,同时发起的多次请求,只有几毫秒的upstream_response_time,而单独访问时则200+毫秒

一开始以为是并发问题,但是量不大,而且用到了epoll

所以,直接查看web.xml中的fiter,对CharacterEncodingFilter进行debug,抓取到如下异常

org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is java.lang.IllegalStateException: Could not get HttpServletRequest URI: Illegal character in hostname at index 10: http: //amp_server:80/reventondc/amp/r/f.kinja-static.com/assets/fonts/elizabeth-serif/elizabethserif-bold-webfont.woff2?09162015

发现是下划线的问题,因为是测试环境,没有用$host,直接传过来了upstream的名称,因为带有下划线,所以报错

后面改成用host,问题解决

但是多次请求有问题,单次请求就可以,初步判断是spring的小bug,回头跟进一下,待续

 

posted on 2017-02-20 19:45  GOvoid  阅读(1324)  评论(0编辑  收藏  举报