使用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
}