Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a apache machine which is serving a .js file. That file should be the only file that need to seen.

Edit:

I have configured to do so in my apache like this :

<VirtualHost *:7090>
        ServerAdmin localhost@test.in
        DirectoryIndex test.js
        DocumentRoot /var/www/test
        ServerName test.in
</VirtualHost>


<Location /var/www/test/test.js>
    Order allow,deny
    Allow from all
</Location>

The site address is test.in which points to test.js file in /var/www/test directory. That is working fine. But I wish when the user tries to hit test.in/someurl (which is not available) or some other url than test.in need to give an message with 401 error.

How do I do that?

share|improve this question

closed as not a real question by Nils, Ward, HopelessN00b, Brent Pabst, dunxd Dec 12 '12 at 15:41

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
"points to" is what? A symlink in the filesystem, a redirect, a rewrite? –  Nils Dec 10 '12 at 14:49
    
@Nils: I have setup my virtualhost with the attribute DocumentRoot which is pointing to that file. –  sriram Dec 11 '12 at 11:29
1  
I still dont get it. DocumentRoot` can point to a directory. Not to a file... –  Nils Dec 11 '12 at 22:11
    
Maybe @sriram would like to map the URI / to the test.js resource transparently for the user/client. In that case we can use an Alias directive or a RewriteRule. –  gertvdijk Dec 12 '12 at 1:01
    
@Nils: I have edited my question and added the code which I used to serve the file –  sriram Dec 12 '12 at 6:52

2 Answers 2

The Location directive matches URIs, not directly related to files on the filesystem. I suggest to use Directory and Files instead, like this:

<Directory "/var/www/test">
    Order deny,allow
    Deny from all
    <Files "test.js">
        Order allow,deny
        Allow from all
    </Files>
</Directory>
share|improve this answer
    
Nope now I cant even able to access the test.in. I get forbidden error! –  sriram Dec 10 '12 at 13:11
    
@sriram That was exactly your request if I read correctly. "That file should be the only file that need to seen." So all other files including the default index files should not be accessible, right? –  gertvdijk Dec 10 '12 at 13:18
    
ya but test.in should be given access to the file test.js. But now I couldn't be able to do that. –  sriram Dec 10 '12 at 13:23
    
@gertvdijk <Files> can't have directory paths - try <Files "test.js"> within the <Directory> block? –  Shane Madden Dec 11 '12 at 5:42
    
@ShaneMadden so true! fixed. –  gertvdijk Dec 11 '12 at 9:30

You have specifically allowed access to your test.js file, but you need to disallow access to the overlying folder as well.

<Location /var/www/test/>
    Order allow,deny
    Deny from all
</Location>
<Location /var/www/test/test.js>
    Order allow,deny
    Allow from all
</Location>
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.