Easy Steps to Resolve Tomcat Server Timeout and Connectivity Errors in GCP VM

Troubleshooting Steps to Fix Tomcat Issues

If your Tomcat server is running, but you cannot access it from your browser, several common issues could be causing this problem. Here are some steps to troubleshoot and resolve the issue:

Firewall Rules

Ensure that the firewall rules on your Google Cloud Platform (GCP) VM allow traffic on port 8080. You can check and create a firewall rule in the GCP console:

  • Go to the VM instance details page.

  • Ensure that "Allow HTTP traffic" and "Allow HTTPS traffic" checkboxes are selected.

  • If not, manually create a firewall rule to allow TCP traffic on port 8080. This can be done by navigating to the VPC network section and adding a firewall rule allowing ingress traffic on port 8080 from any IP address.

  • To check firewall rules list using gcloud SDK or CLI, type the following command:

    gcloud compute firewall-rules list

  • To create the rule (if it isn't created) type the following command:

    gcloud compute firewall-rules create allow-tomcat-8080 --allow tcp:8080 --target-tags tomcat-server --description="Allow traffic on port 8080 for Tomcat" --direction=INGRESS --priority=1000 --network=default

  • You can verify on the console as well:

  • Verify your tomcat service is running or not. Type the following command to test and check service should be Active:

    systemctl status tomcat

  • Tomcat Configuration

    Verify that Tomcat is configured to listen on the correct IP address and port. By default, Tomcat may only listen on localhost. Modify the server.xml file to ensure it listens on all interfaces:

    • Edit the server.xml file located in the Tomcat conf directory.

    • Ensure the Connector element for port 8080 looks like this

      <Connector port="8080" protocol="HTTP/1.1"

      connectionTimeout="20000"

      redirectPort="8443"

      address="0.0.0.0" />

    • To check and edit the server.xml file in your Tomcat installation, follow these steps:

      SSH into your VM

    • Connect to your Google Cloud Platform (GCP) VM instance using SSH.

      Navigate to the Tomcat Configuration Directory

    • Change to the directory where Tomcat is installed. By default, this is usually /opt/tomcat.

      cd /opt/tomcat

      Locate the server.xml file

    • The server.xml file is located in the conf directory inside your Tomcat installation directory

      cd conf

      Open the server.xml file for editing

    • Use a text editor like nano or vim to open the server.xml file. For example, using vim:

      sudo vim server.xml

      Edit the server.xml file

    • Look for the <Connector> element for port 8080 and ensure it is configured to listen on all IP addresses by setting the address attribute to 0.0.0.0.

      <Connector port="8080" protocol="HTTP/1.1"

      connectionTimeout="20000"

      redirectPort="8443"

      address="0.0.0.0" />

      Save and exit the editor

    • If using nano, you can save the file by pressing Ctrl + O, then Enter, and exit by pressing Ctrl + X.

      Restart Tomcat

    • After making changes to the server.xml file, restart the Tomcat service to apply the changes.

      sudo systemctl restart tomcat

After applying all changes your tomcat will be UP.

If you want to install Tomcat server on your VM, follow my blog post.

0
Subscribe to my newsletter

Read articles from Karan Singh Rajawat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Karan Singh Rajawat
Karan Singh Rajawat

I am a Senior Software Engineer at Cross Country Healthcare. I have 8+ year experience in Infrastructure and CloudOps and three AWS certifications: Cloud Practitioner, Solutions Architect - Associate, and SysOps Administrator - Associate. I started my career as a Service Desk Engineer, where I built a strong foundation in IT support and customer service. I then transitioned to on-premise infrastructure, where I gained valuable experience in diverse technologies and platforms. Inspired by the rapid growth of cloud computing, I specialized in AWS CloudOps.