报错场景


访问请求第一次 OK ,第二次 unkown the request

解决方法


  1. 查看反向代理的配置是否出错
    server {
    location /api {  
        default_type  application/json;
        #internal;  
        keepalive_timeout   30s;  
        keepalive_requests  1000;  
        #支持keep-alive  
        proxy_http_version 1.1;  
        rewrite /api(/.*) $1 break;  
        proxy_pass_request_headers on;
        #more_clear_input_headers Accept-Encoding;  
        proxy_next_upstream error timeout;  
        # proxy_pass http://127.0.0.1:8081;
        proxy_pass http://backend;
    }
    }
    upstream backend {
    server 127.0.0.1:8081 max_fails=5 fail_timeout=10s weight=1;
        server 127.0.0.1:8082 max_fails=5 fail_timeout=10s weight=1;
    }  
    

发现,之前做集群任务时,使用了两个端口进行代理,因此导致 一次成功,另一次失败

  1. 注释掉不用的端口

    upstream backend {
        server 127.0.0.1:8081 max_fails=5 fail_timeout=10s weight=1;
    # server 127.0.0.1:8082 max_fails=5 fail_timeout=10s weight=1;
    }  
    
  2. 重启服务

    nginx.exe -s stop
    nginx.exe
    
  3. 问题解决