使用HttpURLConnection发送GET请求,请求的格式如下:
http://hadoop000/log?idsite=3&server_time=1573288345000&country=Spain&os=Win8&city=Spain&ip=214.6.55.89&channel=others&idvisitor=486f06aa533267b&time_spent_ref_action=3440&oid=9af3021e78344b1b83e32c951256d628&userName=100399&type=1&resolution=1280x800&url=mail.163.cn&money=1988&local_time=1573288293000&visitReturning=0&visit_total_time=4082&browser=Chrome&browserVersion=27&storeName=book006&lang=en®ion=Spain
要实现的功能是Java发送GET请求给Nginx,Nginx将请求的URL保存到access_log指定的文件中,发现报FileNotFoundException异常。原因在于Nginx的配置有误,由于数据上报过程中,/log只是作为一个匹配的路径,并不需要给客户端返回任何内容,而Nginx会默认去找root指定的项目目录,并且根据index按顺序查找对应的index文件(例如index.html index.htm等),实际上文件并不存在,就会抛出异常。正确的配置是,在location中最后一行返回200响应码即可
location =/log {
#root /usr/share/nginx/html;
access_log /opt/data/access.log bigdata;
return 200
}