• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help with 404 error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

On a Tomcat 7 installation  on CentOS 7, I have defined a context alias in /usr/local/tomcat/conf/context.xml . This is common practice for many installations I manage, it normally works 100%.

Yet here that alias and its content are giving me 404 errors.

The context alias is called "calllogs" and points to "/home/myuser/myfolder"

Tomcat runs under myuser account.

Therefore I can't see why any entries under /home/myuser/myfolder  would return a 404 when accessed through the context alias. I have also enabled dir listings, and I can't see host:8080/calllogs, it also gives me 404. It's as if the context alias is completely missing.

A different server at the same customer does not have this problem. The only difference between the two servers is that the problematic one has a Selinux-enabled kernel. Could this be the root cause? Selinux is set to permissive.

On the non-problematic server I can see host:8080/calllogs listing, plus all files that live under /home/myuser/myfolder, e.g. I can see  /home/myuser/myfolder/myfile.txt via
host:8080/calllogs/myfile.txt, as one would expect.

This problem is a show-stopper for me so I'd appreciate your help.

Thanks a lot,

George

 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, George!

Actually I have no idea how you ever got anything to work ever doing it like that.

First, you really shouldn't treat Tomcat like it's some sort of file server. Tomcat is a webapp server, so you cannot just drop files wherever you like. You need to have things aranged in proper webapp (WAR) format. In fact, strictly speaking, a webapp should "always" be a WAR file, but Tomcat, like many popular webapp servers will accept something that looks like an unzipped ("exploded") WAR file.

I think you have been more or less doing that, but I did want to stress that "files" aren't technically what Tomcat works with. Tomcat works with webapp resources, and files in an exploded WAR are only one possibility.

As for the context, Tomcat is normally going to look for context files in the following locations:

A) As a WEB-INF/context.xml file in a WAR
B) As an external context file (overrides A, and I'll say more shortly)
C) Synthesizing a basic context using deducible properties such as the WAR file (directory) name.

You're looking for option B, which is the one that overrides C and A (in that order). The location for such a file by default MUST be in TOMCAT_HOME/conf/Catalina/localhost. The context path that Tomcat will assign is the basename of that file (minus the ".xml" extension). Tomcat will ignore any context path defined in that file. This is one of several counter-intuitive things about Tomcat. The context XML file can point to a codeBase in a WAR file or exploded WAR directory anywhere in the OS filesystem tree, but the actual context name is based on its filename, not the path in the Context XML element.

Hope that helps. If you do have concerns about selinux, usually you'll find the info in /var/log/audit and I recommend using the audit2why and audit2allow utilities to sort through that file and give a useful synopsis.
 
George Dev
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured out the solution to my problem, this installation runs Tomcat v8 and aliases need to be defined differently than in v7. Once I defined it properly it worked nicely.

I'm using Tomcat primarily as an app server with webapps in .war format. I'm also taking advantage of its ability to serve static content using the alias in question. It's a small side-task that it performs nicely so no worries from me at all.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
404 Error means that the page you were trying to reach on a website could not be found on their server.
404 not found error messages are generally obtain by Individual websites.

How to fix the error '404 Not Found: To solve the 404 problem, here are some step.

1.Reload the page
2.Check the URL
3.Go back through the directory levels
4.Use the website’s search function
5.Use a search engine
6.Delete the browser cache and cookies
7.Contact the website
reply
    Bookmark Topic Watch Topic
  • New Topic