Ubuntu: Apache is not serving files from the “javascript” directory

This strange issue occurred today on one of the new servers I prepared. I moved the test website from my client’s machine and I was testing it to check what is working and what is not.

Suddenly I noticed that the javascript files stored in the “javascript” directory are causing 404 (not found) errors. One of the files I tried to load was https://testserver.com/javascript/PopupWindow.js

I checked the following:

  • if the file exists (it existed)
  • if the permissions are fine (were fine)
  • if the test.txt file from the same directory is loaded (was NOT loaded!)
  • if the same file is available if moved to another directory (and the file was AVAILABLE!)

So, it looks like the issue lies in the “javascript” directory itself. I turned on detailed logging in Apache (by adding “LogLevel debug” to my site configuration) and this is what I found in the logs:

[date] [client] AH00128: File does not exist: /usr/share/javascript/PopupWindow.js

It surfaced that it was trying to load my script from the “/usr/share/javascript/” directory instead of the website directory. This was strange… I started to dig in the Apache configuration:

# cd /etc/apache2/
# grep javascript -R *
conf-available/javascript-common.conf:Alias /javascript /usr/share/javascript/
conf-available/javascript-common.conf:<Directory "/usr/share/javascript/">
conf-enabled/javascript-common.conf:Alias /javascript /usr/share/javascript/
conf-enabled/javascript-common.conf:<Directory "/usr/share/javascript/">

Here is the thing! There is an alias defined to switch all “/javascript” requests to the “/usr/share/javascript” directory! So the solution was simple. I commented out the Alias in the “javascript-common.conf” file. Once the alias was commented and the server restarted, the files are served properly. Fortunately, this was an easy one 🙂