How to allow only certain files in Apache?

Apache returns 404 for an existing file

  • Apache web server is insisting that the page we are trying to access is missing, but we know it isn't so. We have an installation of Oracle Application Server (actually, more than one, but different servers). This product uses the Apache web server to serve its web pages. We are accessing apache directly without going through any of the Oracle services, so none of the Oracle parts should be affecting this scenario. One of our servers will allow access to files in a certain directory. The others will not. We cannot find any .htaccess file or any statement in httpd.conf that seems to restrict the directory. Apache returns a 404 error. The access_log indicates a 404 error, there is no corresponding entry in the error log. To make it more confusing, only two specific directory names are at issue. It is not a permissions problem on the files; if I take a directory that can be read and simply rename it to the offending directory name, the file under it will no longer be readable and return 404. Renaming it back makes it work again. The parent directory of the offending directories can be accesses without problems. I am unsure as to how to proceed. Is there a way to make Apache reveal where on the filesystem it is looking for the file? Some way to test whether or not Apache would allow access to a specific directory based on its config, or a way to trace so that it explains why it thinks the file is 404? Inquiring minds want to know.

  • Answer:

    URLs are case-sensitive. Are you using an upper case character instead of a lower case one, or vice versa?

splice at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

OK, some more details from the Oracle side: Directory /mydir is set as a mount point for OC4J_BI_Forms. It is used to test reports. I can access /mydir/testfile.html from the web server. There is a directory for jsp files under this, /mydir/jsp. I can access the jsp reports under that, no problem. However, if I create /mydir/jsp/testfile.html and try to access it via the web, 404 error. The file in question is world readable. Que?

splice

As long as we "solved" this I may as well post a follow-up. Oracle AS 10g2 release 2 (10.1.2.2) included new security "features" in the OC4J components and will no longer read files over symbolic links. A lot of the confusion stemmed from the fact that if the server saw the file in a normal directory and you later removed that directory and replaced it with a link, the server would load the file fine until it was restarted. At that point it saw that the file was in a symbolically-linked folder and refused to load the file. No workaround provided by Oracle and so we moved the files out of that directory structure.

splice

It is not a permission issue. From my problem description in the post: It is not a permissions problem on the files; if I take a directory that can be read and simply rename it to the offending directory name, the file under it will no longer be readable and return 404. I appreciate any attempt to help, really, but I am no newbie to Apache, Linux or Oracle Application Server. I have checked the obvious things. dws, this is not selinux. I have a case open with Oracle support. Hopefully they will have a clue about what's going on.

splice

Are you sure that the file on the file system can be read by the process that's running apache? How are you creating the file (or your test files)? With the same user that is the apache user, or another one (like root)? Also make sure that if it's in a subdirectory that the directory has the appropriate access rights for the apache user.

freshgroundpepper

If the box is running selinux, try disabling it. The default security policy imposes some restrictions on what Apache can see, leading to symptoms such as you describe.

dws

I get 404's when apache doesn't have read access to the file. Just another thought....

cdmwebs

Yeah, the problem is that I can't find a location handler for the jsp subdirectory, but the parent is handled by the OC4J_BI_Forms so I imagine it is handled by that as well. If anyone has a clue as to this behaviour from the Oracle side, I'd appreciate any help.

splice

Or, like you just said and I failed to read properly, something on the oracle side is set up to handle regular HTML files on the working server, and not on the broken ones. But it you can't find that, you might get away with narrowing down what gets passed off to oracle in the first place by giving the Location tag something like /*.jsp instead of the entire directory.

dreadpiratesully

I would expect files in the jsp directory to be given a special handler of some sort (like your servlet engine). Check for a 'Location /jsp ' stanza or something like that in the httpd.conf. Yeah, on preview...angle brackets just aren't cool.

dreadpiratesully

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.