zoukankan      html  css  js  c++  java
  • Nginx报错——upstream timed out 10060

    前言

    在部署项目的时候,Nginx 启动不了,网上看了很多大佬的文章, 最后发现是 Windows 服务器 IP 解析的问题。

    过程

    部分 error.log:

    2018/12/25 19:45:55 [notice] 2368#2644: signal process started
    2018/12/25 19:47:10 [error] 5024#3948: *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: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8090/", host: "127.0.0.1:8088"
    

    首先确认代理的地址没有错误。

    据网上给出的方法,我也试过在 Nginx 的配置文件中加上代理超时连接的相关参数,但还是没有解决:

    proxy_connect_timeout 1; 
    proxy_send_timeout 30; 
    proxy_read_timeout 60; 
    

    最后翻到一篇文章,写到 win10默认的是ipv6的解析,而ipv6默认解析到【::1】而不是127.0.0.1。所以我们nginx配置文件里面是连接不到本地的tomcat,一直处于timeout的状态win10 tomcat nginx upstream timed out 10060 —— 做你的老王

    我试了试在服务器上 ping localhost,发现确实存在问题:localhost 被 Windows 解析为了 ::1

    当然,应该可以用系统注册表里修改 Windows IP 解析的优先级的方法。也就是提高 IPv4 的优先级,使localhost 解析为 127.0.0.1。具体方法博文中有。

    不过我看了下 Nginx 的配置文件

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
     
        sendfile        on;
        keepalive_timeout  65;
     
        #gzip  on;
     
        server {
            listen       80;
            server_name  localhost;
            location / {
                proxy_pass http://127.0.0.1:9090;
        }
        location ~.(css|js|png|ttf|woff|woff2|eot|svg|map|jpg|gif)$ {
               root E:/project/tomcat_with_jdk_hsqldb_springboot/tomcat-8.5.23/webapps;
        }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }
    

    server 里的我单独拎出来:

        server {
            listen       80;
            server_name  localhost;
            location / {
                proxy_pass http://127.0.0.1:9090;
        }
    

    我尝试着把它改为:

        server {
            listen       80;
            server_name  127.0.0.1;
            location / {
                proxy_pass http://127.0.0.1:9090;
        }
    

    再测试,Nginx 正常运行。也就是说可以不通过修改系统注册表的方式,来解决这个问题。

    另外还要提到一点,我的服务器环境是 Windows Server 2008 R2,看来不止 Windows10 有这个问题啊。

    参考

    1. win10 tomcat nginx upstream timed out 10060 —— 做你的老王
  • 相关阅读:
    Scrum 冲刺博客第五篇
    Scrum 冲刺博客第四篇
    Scrum 冲刺博客第三篇
    ajax send()
    form action中get post传递参数的问题
    struts2 iterator中if标签的使用
    表格内容自动换行
    从js向Action传中文参数出现乱码问题的解决方法
    java开发环境搭建
    Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/
  • 原文地址:https://www.cnblogs.com/Sherlock-J/p/12925942.html
Copyright © 2011-2022 走看看