Syntax highlighter header

Friday 24 September 2021

Httpd mod_proxy throwing 503 error

Recently I was debugging an issue of Apache server throwing 503 when we are trying to connect to a nodeJS server running on port 5000. We had proxy setting correctly added into out httpd.conf

<IfModule mod_proxy.c>
    ProxyRequests Off
    SSLProxyEngine On

    <Proxy *>
            Order deny,allow
            Allow from 127.0.0.1
    </Proxy>

    <Location /nodeserver>
        ProxyPass http://localhost:5000
        ProxyPassReverse http://localhost:5000
    </Location>

</IfModule>

The server was throwing 503 error and we were not able to figure out the reason for it because node server was up and was responding to all requests at port 5000. But when we were trying to access it via Apache server it was throwing 503 error. 

After a lot of debugging we found that it was selinux which was preventing Apache server from connecting to node server at port 5000. Although Apache server was able to connect tomcat server running at port 8009. 

The reason of this selective behavior was that selinux defines some ports as http ports and httpd server is allowed to connect to those port. You can get a list of these ports by running following command.

$semanage port -l |grep http_port_t
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000

After changing port from 5000 to 9000 for our node server and changing mod_proxy setting in httpd.conf our application started working.


 

Wednesday 8 September 2021

Tomcat 9 creates different sessions for different directories

Recently we were testing one application with tomcat 9.0.43 where one application path was starting with sso/ and one was starting with normal/. We were redirecting to normal/ path from sso/ path. We found that the values we set in HttpSession were missing in normal/ path. 

After a lot of debugging we found out that Tomcat 9 was creating two sessions for same client one for sso/ path and one for normal/ path. That is why values set in HttpSession were missing. I wrote following sample jsp file to demonstrate the behavior.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<%
	String sessionStr = request.getSession().toString();
%>
Session:<%=sessionStr%>

</body>
</html>

I placed the file at two locations. One under sso/index.jsp and one under normal/index.html and hit both of them from same browser and output was following.

SSO:    Session:org.apache.catalina.session.StandardSessionFacade@2ca7ac8e
Normal: Session:org.apache.catalina.session.StandardSessionFacade@4b992f7e

This problem looks like to be fixed in tomcat 9.0.54