tomcathttp-redirectload-balancingnginx-configgeoserver

ERR_TOO_MANY_REDIRECTS error occurs in load balanced geoserver with nginx


I'm trying to form 2 load-balanced NginX web servers, which is connected to 2 Tomcat WAS servers. But when connecting to a address with context, it often makes too many redirections generating ERR_TOO_MANY_REDIRECTS.

This does not happen when I map only 1 WAS Server in the NginX upstream option, and does not occur when I send request to the web application mapped at root path.

I want to keep both my http and https connections, and keep my context path as it is.(Unless there is no other option)

The below are my server settings.(Tomcat and NginX)

I have 2 tomcat servers running, each has 2 web applications with contexts set like below.(server.xml)

<Context docBase="UTIS_MAP_GATEWAY" path="/" reloadable="true"/>
<Context docBase="geoserver" path="/geoserver" reloadable="true"/>

And set some session clustering options(server.xml)

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
          <Manager className="org.apache.catalina.ha.session.DeltaManager"
               expireSessionsOnShutdown="false"
               notifyListenersOnReplication="true"/>
          
          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
          
          <Membership className="org.apache.catalina.tribes.membership.McastService"
                              address="228.0.0.4"
                              port="45564"
                              frequency="500"
                              dropTime="3000"/>
               
          <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                              address="192.168.20.199"
                              port="4000"
                              autoBind="100"
                              selectorTimeout="5000"
                              maxThreads="6"/>

          <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
          <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
          </Sender>
               
          <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
          <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>

          </Channel>
      </Cluster>

the IPs are ~.~.~.198 and 199, so I set load balancing in the nginx configuration. gis is the only file in sites-enabled directory.

# cat /etc/nginx/sites-enabled/gis
upstream gis-proxy {
    least_conn;
    server 192.168.20.198:8080;
    server 192.168.20.199:8080;
}
# cat /etc/nginx/includes/gis_location.conf
location / {
        proxy_pass      http://gis-proxy/;

        include /etc/nginx/proxy_params;
}
# cat /etc/nginx/proxy_params
proxy_pass_header Set-Cookie;
proxy_http_version 1.1;
proxy_set_header "Connection" "";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Scheme $scheme;

I wanted to use both http and https, so I set the default.conf like below.

# cat conf.d/default.conf
server {
        listen 80;
        listen [::]:80;
        server_name gis.utic.go.kr;

        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_certificate         /home/utigis/ssl/_wildcard_.utic.go.kr_20230913BBCDC.crt.pem;
        ssl_certificate_key     /home/utigis/ssl/_wildcard_.utic.go.kr_20230913BBCDC.key.pem;
        ssl_protocols           TLSv1.2 TLSv1.3;
        ssl_ciphers             HIGH:MEDIUM:!SSLv2:!PSK:!SRP:!ADH:!AECDH:!EXP:!RC4:!IDEA:3DES;

        include /etc/nginx/includes/gis_location.conf;
}
# cat /etc/nginx/nginx.conf
...
http {
  ...
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

And NginX is running in ~.~.~.198.

Whenever I connect to "~.198/geoserver/" it keeps on redirecting, calling the context root with and without the number GET parameter repeatedly.

Chrome DevTools network tab

Which part of the configuration should I change to make ERR_TOO_MANY_REDIRECTS occur?


Solution

  • I had to set the WebUI settings to DO_NOT_REDIRECT in Geoserver global settings.

    In the Geoserver Web Interface, go to Settings > Global Menu

    enter image description here

    Then Change the WebUI Mode setting to DO_NOT_REDIRECT. This solved my problem.

    enter image description here