Richard T asked:
[Thu Dec 08 12:08:26.643037 2016] [cgi:error] [pid 27403] [client xx.xx.xx.xx:46247] AH01215: (8)Exec format error: exec of ‘/usr/www/http/js/test.js’ failed, referer: http://example.com/test/jstest.html [Thu Dec 08 12:08:26.643548 2016] [cgi:error] [pid 27403] [client xx.xx.xx.xx:46247] End of script output before headers: test.js, referer: http://example.com/test/jstest.html
Here, of course, xx.xx.xx.xx is the IP of the server, “example.com” is the domain in question, and the path ‘/usr/www/http’ is the top level directory Apache serves this domain’s web site from.
I’ve read a lot of materials on this and I know the Apache configuration files matter… I’ve tried setting a ScriptAlias and have a few questions about it I can’t seem to find clarity on:
- Just how are scripts in the “ScriptAlias” directory refered to in
the HTML code – start with a slash? Is there some special character
to say “top of site?” And;
- Is there only one unique ScriptAlias directory permitted for the
whole site, or can one have multiple directories that are searched –
and if so, how do you specify them, multiple definitions of
ScriptAlias, comma separated list, etc? And;
- Can we set one per VirtualHost? And do we do this by putting a
ScriptAlias inside the Virtual Host definition?
To make testing a little easier I made multiple instances of almost the same code in files of the same name in various directories, and altered the contents slightly so I could easily determine which location had taken effect with what kind of a call, all the while looking at the Apache logs. Here’s an example from one of these files:
var myHeading = document.querySelector('h2'); myHeading.textContent = 'website top level js dir';
This code takes the first tag and replaces whatever the content was with whatever
textContent is provided in the second line. Obviously, I was changing the
textContent to match what the location was.
In the HTML, any reference like any of these worked so long as the calling page was either in the same directory as test.js or in a parent directory or if there was a link to test.js that was either in the same directory or a subdirectory:
<script src="test.js"></script> <script src="js/test.js"></script> <script src="http://example.com/test/js/test.js"></script>
In the HTML, any reference like these always failed no matter what I tried so long as the calling html was not in the same directory or a parent directory:
<script src="/js/test.js"></script> <script src="/usr/WWW/http/js/test.js></script> <script src="http://example.com/test/js/test.js"></script>
The directories and files involved are all owned by my personal UID and GID (as they always have been), and their permissions are all 755.
There’s a global ScriptAlias defined as (also tried variations on this):
ScriptAlias /js/ "/usr/www/js/"
There’s another ScriptAlias entry in the Virtual Host definition – no idea if it does anything! No effect so far as I can yet see. … And, there are Directory entries like this in the main config file for all the directories I tried:
<Directory /usr/www/http/js/> AllowOverride None Options ExecCGI Require all granted </Directory>
Fredi wanted a tree. Fine:
The tree starts at the Virtual host’s document root – who cares where? From there:
├── index.html ├── js │ └── test.js └── test ├── js │ └── test.js └── testjs.html 3 directories, 4 files
This is not what
ScriptAlias is intended for. Remove it from your configuration.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.