how to create a VirtualHost to serve only static content
Asked Answered
M

1

8

I want to create a virtual host in apache such that it serves only static content like stylesheets, videos, images, javascripts, text files, etc. I am not looking at any "processing" capabilities from this virtual host.

Mucro answered 24/6, 2010 at 17:52 Comment(1)
To extend the question, a good answer would include directives "to inform the browser to keep files in its own cache" and "to have be cookieless requests".Rowdyism
I
11

Create a VirtualHost entry as follows:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName media.domain.tld

    DocumentRoot "/Library/WebServer/Documents/media"

    ErrorLog "/private/var/log/apache2/media-error_log"
    CustomLog "/private/var/log/apache2/media-access_log" common

    <Directory /Library/WebServer/Documents/media>
    Order deny,allow
    Allow from all
    SetHandler default-handler
    </Directory>

</VirtualHost>
Immaterialism answered 7/7, 2010 at 11:27 Comment(4)
I removed the ServerAdmin, ServerName and all those lines pertaining to logs and then restarted apache. I observe it is serving php filesMucro
@deostroll: I updatd my answer to fit your needs.Immaterialism
it didn't work as expected. Do we still need the Location tag?Mucro
@deostroll: you can remove Location, SetHandler can be placed inside the Directory tag, too. Change its value to default-handler.Immaterialism

© 2022 - 2024 — McMap. All rights reserved.