My Tomcat application returns 404 code when accessing

I am trying to access an unpackaged Java application I dropped as a .war file inside the /opt/bitnami/apache-tomcat/webapps/ directory. I am able to access the tomcat /manager page along with the /phpmyadmin page. I am unable to access to Java application and receive a 404.

AWS AMI used: bitnami-tomcatstack-8.5.20-0-linux-ubuntu-14.04-x86_64-hvm-ebs-mp-03e71f1e-8599-4fc7-ab8a-2fcfbcb81353-ami-37c7f64c.4 (ami-04e5c761)

I followed these steps and created the following.

  • sudo mkdir /opt/bitnami/apache-tomcat/webapps/myapp/conf
  • created the file httpd-prefix.conf inside the newly created conf directory
  • added the Include "/opt/bitnami/appache-tomcat/webapps/myapp/conf/httpd-app.conf" to the httpd-prefix.conf file
  • create the httpd-app.conf inside the newly created conf directory
  • added the following to httpd-app.conf:
    <Location /myapp> ProxyPass ajp://localhost:8009/myapp </Location>
  • restarted apache (and other utils)

None of the addresses below work. I receive a 404 when I try to access the application.

  • 127.0.0.1:8888/myapp
  • 127.0.0.1/myapp
  • PUBLIC-IP/myapp

Here is the catalina.out of the .war file being successfully deployed (exstretch.war is .war file name):

07-Oct-2017 13:48:17.426  INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR 
Deploying web application archive [/opt/bitnami/apache-tomcat/webapps/exstretch.war]

Here is what the END of the httpd.conf file looks like in the /opt/bitnami/apache2/httpd.conf file:
<Location /test>
ProxyPass ajp://localhost:8009/exstretch

ProxyPass /exstretch/ http://localhost:8009/exstretch
ProxyPassReverse /exstretch/ http://localhost:8009/exstretch

Any help on accessing the application would be so helpful!

Hello @brock.tubre,

I think you didn’t follow these instructions properly.

You should have created /opt/bitnami/apps/myapp/conf folder instead and place the apache configuration files (httpd-prefix.conf and httpd-app.conf) inside that directory.

There is a typo in the path (appache) and also the line should be Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"

I hope it helps,
Tomas

Thanks @tomasp,

I hand typed most of the instructions in original post and did have some typos. I took your advice and moved the Java application to the /opt/bitnami/apps directory and now have the following. Even after making the changes below I am still producing the same results as before. 404 when accessing my Java application.

Here is what is inside /opt/bitnami/apps directory
/opt/bitnami/apps/exstretch/conf/httpd-prefix.conf
and
/opt/bitnami/apps/exstretch/conf/httpd-app.conf

Inside the /opt/bitnami/apps/exstretch/conf/httpd-prefix.conf file is:

Include "/opt/bitnami/apps/exstretch/conf/httpd-app.conf"

Inside the /opt/bitnami/apps/exstretch/conf/httpd-app.conf

<Location /exstretch>
ProxyPass ajp://localhost:8009/exstretch
</Location>

Inside the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file is:

# Bitnami applications installed in a prefix URL
Include "/opt/bitnami/apps/phpmyadmin/conf/httpd-prefix.conf"
Include "/opt/bitnami/apps/exstretch/conf/httpd-prefix.conf"

I know that there are no syntax errors, or misplaced/missing files because restarting services using /opt/bitnami/ctlscript.sh restart produces no errors:

Syntax OK
/opt/bitnami/apache2/scripts/ctl.sh : httpd stopped
Using CATALINA_BASE:   /opt/bitnami/apache-tomcat
Using CATALINA_HOME:   /opt/bitnami/apache-tomcat
Using CATALINA_TMPDIR: /opt/bitnami/apache-tomcat/temp
Using JRE_HOME:        /opt/bitnami/java
Using CLASSPATH:       /opt/bitnami/apache-tomcat/bin/bootstrap.jar:/opt/bitnami/apache-tomcat/bin/tomcat-juli.jar
Using CATALINA_PID:    /opt/bitnami/apache-tomcat/temp/catalina.pid
Tomcat stopped.
/opt/bitnami/apache-tomcat/scripts/ctl.sh : tomcat stopped
/opt/bitnami/mysql/scripts/ctl.sh : mysql stopped
171009 14:23:55 mysqld_safe Logging to '/opt/bitnami/mysql/data/mysqld.log'.
171009 14:23:55 mysqld_safe Starting mysqld.bin daemon with databases from /opt/bitnami/mysql/data
/opt/bitnami/mysql/scripts/ctl.sh : mysql  started at port 3306
Using CATALINA_BASE:   /opt/bitnami/apache-tomcat
Using CATALINA_HOME:   /opt/bitnami/apache-tomcat
Using CATALINA_TMPDIR: /opt/bitnami/apache-tomcat/temp
Using JRE_HOME:        /opt/bitnami/java
Using CLASSPATH:       /opt/bitnami/apache-tomcat/bin/bootstrap.jar:/opt/bitnami/apache-tomcat/bin/tomcat-juli.jar
Using CATALINA_PID:    /opt/bitnami/apache-tomcat/temp/catalina.pid
Tomcat started.
/opt/bitnami/apache-tomcat/scripts/ctl.sh : tomcat started
Syntax OK
/opt/bitnami/apache2/scripts/ctl.sh : httpd started at port 80

IMPORTANT INFO:

  • My Java application runs locally (on my personal machine) on port 8080, this information might also be helpful.

  • Able to access /manager at http://127.0.0.1:8888/manager/

  • Able to access /phpmyadmin at http://127.0.0.1:8888/phpmyadmin/

  • NOT able to access /exstretch at http://127.0.0.1:8888/exstretch/

  • When I use curl -v localhost/manager/ when ssh’d in the server is returns the following:

*   Trying 127.0.0.1...
> * Connected to localhost (127.0.0.1) port 80 (#0)
> > GET /manager HTTP/1.1
> > Host: localhost
> > User-Agent: curl/7.45.0
> > Accept: */*
> > 
> < HTTP/1.1 302 302
> < Date: Mon, 09 Oct 2017 14:38:47 GMT
> < Server: Apache
> < X-Frame-Options: SAMEORIGIN
> < Location: /manager/
> < Content-Length: 0
> < 
> * Connection #0 to host localhost left intact
  • When I use the curl command curl localhost/exstretch when ssh’d into server I am returned:
> *   Trying 127.0.0.1...
> * Connected to localhost (127.0.0.1) port 80 (#0)
> > GET /exstretch HTTP/1.1
> > Host: localhost
> > User-Agent: curl/7.45.0
> > Accept: */*
> > 
> < HTTP/1.1 302 302
> < Date: Mon, 09 Oct 2017 14:39:41 GMT
> < Server: Apache
> < X-Frame-Options: SAMEORIGIN
> < Location: /exstretch/
> < Content-Length: 0
> < 
> * Connection #0 to host localhost left intact

I am just giving you as much info as I have, thank you for your help.

  • Brock T

Hi,

Let us do a small test to check that your Apache rules are being applied. Could you change

<Location /exstretch>
ProxyPass ajp://localhost:8009/exstretch
</Location>

to

<Location /exstretch>
ProxyPass ajp://localhost:8009/phpmyadmin
</Location>

If the rule is being applied, then phpmyadmin should be shown. If that is the case, then there is something wrong with the .war file. Could you then show the output of this command?

sudo ls /opt/bitnami/apache-tomcat/webapps -la

Hope it helps.

Best regards,

Javier J. Salmerón


Was my answer helpful? Click on :heart:

@jsalmeron @tomasp Thanks for the response.

I changed the file located at /opt/bitnami/apps/exstretch/conf/httpd-app.conf , and it now reads the following:

<Location /exstretch>
ProxyPass ajp://localhost:8009/phpmyadmin
</Location>

and then restarted services.

I then tried to navigate to the url http://127.0.0.1:8888/exstretch and received a 404.

HTTP Status 404 – Not Found
Type Status Report
Message /phpmyadmin
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.20

This means that the configuration ARE taking effect. I am certain that there is nothing wrong with the .war file because I was able to launch the Java application using AWS Elastic Beanstalk service and the same .war file and access application without issues.

Here is the output from the command sudo ls /opt/bitnami/apache-tomcat/webapps -la

total 37112
drwxr-xr-x  8 tomcat  tomcat     4096 Oct 10 12:30 .
drwxr-xr-x 10 root    root       4096 Aug 14 14:06 ..
drwxr-xr-x 14 tomcat  tomcat     4096 Aug 14 14:06 docs
drwxr-xr-x  6 tomcat  tomcat     4096 Aug 14 14:06 examples
drwxr-x---  5 tomcat  tomcat     4096 Oct 10 12:30 exstretch
-rw-r--r--  1 root    root   37968841 Oct 10 12:29 exstretch.war
drwxr-xr-x  5 tomcat  tomcat     4096 Aug 14 14:06 host-manager
drwxr-xr-x  5 tomcat  tomcat     4096 Aug 14 14:06 manager
drwxr-xr-x  4 bitnami tomcat     4096 Aug 14 14:09 ROOT

Since @tomasp told me to follow these instructions more carefully, I copied the exstretch expanded directory into the /opt/bitnami/apps directory.

IMPORTANT NOTES:
http://127.0.0.1:8888/phpmyadmin shows the phpmyadmin login page successfully.

Hi,

I see something strange in the webapps folder, let us try the following:

  • Stop tomcat
sudo /opt/bitnami/ctlscript.sh stop tomcat
  • remove the exstretch folder
sudo rm -rf /opt/bitnami/apache-tomcat/webapps/exstretch
  • Change the ownership of the exstretch.war file
sudo chown tomcat:tomcat /opt/bitnami/apache-tomcat/webapps/exstretch.war
  • Restart tomcat
sudo /opt/bitnami/ctlscript.sh restart tomcat

Hope it helps.

Best regards,

Javier J. Salmerón


Was my answer helpful? Click on :heart:

@jsalmeron

Which directory should I have my expanded application residing in?
Here -> /opt/bitnami/apache-tomcat/webapps/
or
Here -> /opt/bitnami/apps

After following the steps above now the ls -la /opt/bitnami/apache-tomcat/webapps/ produces

total 37112
drwxr-xr-x  8 tomcat  tomcat     4096 Oct 11 13:02 .
drwxr-xr-x 10 root    root       4096 Aug 14 14:06 ..
drwxr-xr-x 14 tomcat  tomcat     4096 Aug 14 14:06 docs
drwxr-xr-x  6 tomcat  tomcat     4096 Aug 14 14:06 examples
drwxr-x---  5 tomcat  tomcat     4096 Oct 11 13:02 exstretch
-rw-r--r--  1 tomcat  tomcat 37968841 Oct 10 12:29 exstretch.war
drwxr-xr-x  5 tomcat  tomcat     4096 Aug 14 14:06 host-manager
drwxr-xr-x  5 tomcat  tomcat     4096 Aug 14 14:06 manager
drwxr-xr-x  4 bitnami tomcat     4096 Aug 14 14:09 ROOT

Since following @tomaspand instructions more carefully, I copied the newly exspanded exstretch directory into the /opt/bitnami/apps directory. Which now looks like this:

total 16
drwxr-xr-x  4 root root 4096 Oct 11 13:12 .
drwxr-xr-x 17 root root 4096 Aug 14 14:17 ..
drwxr-x---  6 root root 4096 Oct 11 13:05 exstretch
drwxr-xr-x  5 root root 4096 Aug 14 14:09 phpmyadmin

Once again I am still receiving the same 404 error:

HTTP Status 404 – Not Found
Type Status Report
Message /exstretch/
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.20

Thank you for the help, this is becoming pretty frustrating!!!

Hi,

If I understood correctly, you just copied the folder /opt/bitnami/apache-tomcat/webapps/ to /opt/bitnami/apps/ . This is incorrect as /opt/bitnami/apps/exstretch should contain the apache configuration for forwarding the traffic to your deployed java application in /opt/bitnami/apache-tomcat/webapps/ .

Another thing, previously I wrote a bad example, could you try this instead in /opt/bitnami/apps/exstretch/conf/httpd-app.conf?

<Location /exstretch>
ProxyPass ajp://localhost:8009/manager
</Location>

Restart the server services

sudo /opt/bitnami/ctlscript.sh restart

Please let me know if you get something now. Though you tested your .war file previously, I am pretty sure that there must be something missing (maybe a .xml configuration file or something)

Best regards,

Javier J. Salmerón


Was my answer helpful? Click on :heart:

@jsalmeron You are right I did copy the exstretch directory from /opt/bitnami/apache-tomcat/webapps/ to /opt/bitnami/apps/ AND I also copied to conf folder with the original config files into the /opt/bitnami/apps/exstretch directory.

Here is the output for more /opt/bitnami/apps/exstretch/conf/httpd-app.conf

<Location /exstretch>
ProxyPass ajp://localhost:8009/exstretch
</Location>

Here is the output for more /opt/bitnami/apps/exstretch/conf/httpd-prefix.conf

Include "/opt/bitnami/apps/exstretch/conf/httpd-app.conf"

I am making the following changes now in the /opt/bitnami/apps/exstretch/conf/httpd-app.conf file:

<Location /exstretch>
ProxyPass ajp://localhost:8009/manager
</Location>

I then restarted services using /opt/bitnami/ctlscript.sh restart

Navigated to http://127.0.0.1:8888/exstretch/ brings up the tomcat manager page.

After running the command curl -v localhost/exstretch I get the following output.

*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /exstretch HTTP/1.1
> Host: localhost
> User-Agent: curl/7.45.0
> Accept: */*
> 
< HTTP/1.1 302 302
< Date: Wed, 11 Oct 2017 14:06:17 GMT
< Server: Apache
< X-Frame-Options: SAMEORIGIN
< Location: /manager/
< Content-Length: 0
< 
* Connection #0 to host localhost left intact

It looks like the redirect is working. What does this mean about my .war file?

Hi,

I can’t really tell what happens with the war file, could you check the contents to see if there is some configuration xml file that needs to be created. Could you also check the apache tomcat logs /opt/bitnami/apache-tomcat/logs/ to see if there is some information about the issue?

Best regards,

Javier J. Salmerón


Was my answer helpful? Click on :heart:

Here is the contents of the log files.

catalina.out

12-Oct-2017 01:46:56.050 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/opt/bitnami/apache-tomcat/webapps/exstretch.war]
12-Oct-2017 01:46:59.700 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
12-Oct-2017 01:46:59.843 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/bitnami/apache-tomcat/webapps/exstretch.war] has finished in [3,793] ms

In the localhost.2017-10-12.log I see the following exception being thrown:

12-Oct-2017 01:40:37.802 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.core.StandardContext.listenerStop Exception sending context destroyed event to listener instance of class [ch.qos.logback.classic.servlet.LogbackServletContextListener]
 java.lang.IllegalStateException: java.io.FileNotFoundException: /opt/bitnami/apache-tomcat/webapps/exstretch/WEB-INF/lib/logback-classic-1.1.11.jar (No such file or directory)
	at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:97)
	at org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:260)
	at org.apache.catalina.webresources.StandardRoot.getResourceInternal(StandardRoot.java:281)
	at org.apache.catalina.webresources.Cache.getResource(Cache.java:62)
	at org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:216)
	at org.apache.catalina.webresources.StandardRoot.getClassLoaderResource(StandardRoot.java:225)
	at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2167)
	at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
	at ch.qos.logback.core.ContextBase.getLifeCycleManager(ContextBase.java:260)
	at ch.qos.logback.core.ContextBase.reset(ContextBase.java:175)
	at ch.qos.logback.classic.LoggerContext.reset(LoggerContext.java:220)
	at ch.qos.logback.classic.LoggerContext.stop(LoggerContext.java:348)
	at ch.qos.logback.classic.servlet.LogbackServletContextListener.contextDestroyed(LogbackServletContextListener.java:36)
	at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4790)
	at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5429)
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
	at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:843)
	at org.apache.catalina.startup.HostConfig.undeploy(HostConfig.java:1437)
	at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1363)
	at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1623)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
	at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1164)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1388)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1392)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1360)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.FileNotFoundException: /opt/bitnami/apache-tomcat/webapps/exstretch/WEB-INF/lib/logback-classic-1.1.11.jar (No such file or directory)
	at java.util.zip.ZipFile.open(Native Method)
	at java.util.zip.ZipFile.<init>(ZipFile.java:219)
	at java.util.zip.ZipFile.<init>(ZipFile.java:149)
	at java.util.jar.JarFile.<init>(JarFile.java:166)
	at java.util.jar.JarFile.<init>(JarFile.java:103)
	at org.apache.catalina.webresources.AbstractArchiveResourceSet.openJarFile(AbstractArchiveResourceSet.java:308)
	at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:93)
	... 28 more

Although when I look into the /opt/bitnami/apache-tomcat/webapps/exstretch/WEB-INF/lib/ directory I clearly see the .jar file named logback-classic-1.1.11.jar

-rw-r----- 1 tomcat tomcat  309130 Jun  7 07:59 logback-classic-1.1.11.jar

Any suggestions?
The other 2 log files do not give any relevant information.

Thanks for the help.

I just launch a simple bare-bone spring application, and still get the same results. I receive a 404 when accessing app. Nothing in logs that throw any type of errors.

Is there something I am missing here? Is there a sample .war file I can launch onto the tomcat stack that WILL work?

After turning the Spring application into a Spring web application and creating a web.xml file I was able to get the application to run locally on a bitnami downloaded instance and also on the AWS AMI installed instance. Thanks for the help.

Hi,

Thanks for letting us know :slight_smile: We will close this ticket now. In case you have more issues please open a new thread.

Best regards,

Javier J. Salmerón


Was my answer helpful? Click on :heart: