nginx 10054: An existing connection was forcibly closed by the remote host报错解决方法

在使用nginx过程中,有些通过nginx反向代理转发到tomcat的接口请求莫名被强制取消,以至于无法返回数据,其他接口回数据也很慢,出现这种情况的原因应该是nginx的连接数和tomcat的连接数没有配置好导致。按照下面的方法解决了。
nginx监听接口为80,后台tomcat为82。

1.修改tomcat的server.xml配置。配置信息如下:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
    maxThreads="2048"
    maxHttpHeaderSize="8192"
    minSpareThreads="512"
    maxSpareThreads="1024"
    maxIdleTime="30000"/>
    
    <Connector executor="tomcatThreadPool"
    port="82"
    protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443"
    acceptCount="1024"
    enableLookups="false"
    URIEncoding="utf-8"   
    compression="on"/>

2.修改nginx的nginx.conf文件,配置信息如下:

http{}中添加:

  keepalive_requests 8192;
  keepalive_timeout 180s 180s;

server里的location中添加:proxy_http_version 1.1;

server{
       
  location /api/ {
            #root   gtmcApp;
            #index  index.html index.htm;
            proxy_pass http://172.16.4.120:8580/;
            proxy_http_version 1.1;
            #允许cros跨域访问
            #add_header 'Access-Control-Allow-Origin' '*';
        }
        location /gtmcApp {
            alias   gtmcApp;
            index  index.html index.htm;
        }
        location /gtmcApp/api/ {
            #root   gtmcApp;
            #index  index.html index.htm;
            proxy_pass http://172.16.4.120:8580/;
            proxy_http_version 1.1;
            #允许cros跨域访问
            #add_header 'Access-Control-Allow-Origin' '*';
        }


}

如此,重启tomcat和nginx ,问题解决了。

参考:https://www.cnblogs.com/Jiphen/p/9685047.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容