I have a J2EE application hosted on a linux VPS server. I use nginx as the web server and tomcat6 as the application server. At times, the website keeps waiting to load or sometimes even throws a 504 bad gateway nginx error. During this downtime of a few minutes(typically 3-5 minutes), if I try to access the server via SSH, I get a connection timeout error. When the website starts working after a few minutes, I noticed that tomcat, nginx are still running on the same process id as before. I do not need to restart tomcat or nginx, it starts working by itself. Also once the site is running again, I also notice that the SSH connection to the server also succeeds.
I am not sure where exactly the issue lies? Is it a connectivity issue with the server or is it some error in my config? Any insights would be appreciated.