@marlin
2018-01-03T14:56:41.000000Z
字数 1918
阅读 3898
localhost
nginx
pending
在进行动静分离本地调试时,出现了nginx连接后台tomcat服务器不成功的问题。
通过查看日志发现如下:
access.log中的部分关键日志
127.0.0.1 - - [03/Jan/2018:14:19:19 +0800] "GET /security/getPublicKey1.go HTTP/1.1" 200 310 "http://localhost/dist/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
127.0.0.1 - - [03/Jan/2018:14:20:19 +0800] "POST /security/login.go HTTP/1.1" 200 95 "http://localhost/dist/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
error.log中的部分关键日志
2018/01/03 14:18:52 [error] 1984#5672: *1 CreateFile() "D:\_Software\nginx-1.12.2/html/dist/js/echarts.js.map" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /dist/js/echarts.js.map HTTP/1.1", host: "localhost"
2018/01/03 14:20:19 [error] 1984#5672: *1 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "POST /security/login.go HTTP/1.1", upstream: "http://[::1]:9898/security/login.go", host: "localhost", referrer: "http://localhost/dist/"
2018/01/03 14:20:20 [error] 1984#5672: *1 CreateFile() "D:\_Software\nginx-1.12.2/html/api/currentUser" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /api/currentUser HTTP/1.1", host: "localhost", referrer: "http://localhost/dist/"
可以看出前后两个请求(以GET和POST来说)间隔达到了1分钟(计算时间戳差值),而在POST的同一时刻在error中抛出了upstream timed out
异常,并给出了错误编号10060
,通过搜索得到一些关键信息,见这里,简单来说就是localhost被解析成了ipv6的格式。
通过在命令行中简单实验,发现确实如博文中所说,localhost没有解析成常见的127.0.0.1的格式。这在error日志中同样可以看出端倪:upstream: "http://[::1]:9898/security/login.go"
。
按照博文中的提示修改注册表并重启电脑后,ping确实能够发现localhost解析成了ipv4的格式。但nginx的日志依然如故。这里为不再纠结,简单将upstream的配置进行修改如下:
upstream ajaxServer{
- server localhost:9898;
+ server 127.0.0.1:9898;
keepalive 16;
}
经此修改之后,再进行请求时一切就顺畅了。