Web-server – How to configure apache2 to serve static assets from server root subdirectory

apache-2.2static-contentweb-server

Front end developer here – I just inherited a server (Mac Pro) to host my prototypes within our network. There's already an apache server set up on it, but I don't know much about it's config. This is a shared server, so while the server root is set up at /Users/Shared, I only have permissions to place my prototypes at

/Shared/mydiv/mydept/prototypes

I build my site with webpack and it places static assets in a dist directory. The server configuration is working; users can browse to sharedserver.url.com/mydiv/mydept/prototypes and the index.html is served correctly.

The problem is that index.html references scripts.js, also located within the dist directory, but the web server is looking for them in the server root at sharedserver.url.com, which obviously returns a 404.

I'm referencing scripts in index.html like this:

<script src="scripts.js"></script>

Likewise, I need to reference some fonts located in dist/fonts.

sharedserver.url.com/   <-- APACHE TRYING TO ACCESS STATIC ASSETS HERE
|_mydiv/
   |_ mydept/
      |_ prototypes/
         |_ _ dist/
                |_ index.html
                |_ scripts.js  <-- REALLY WISH APACHE LOOK FOR STATIC ASSETS HERE 
                | _ _fonts/
                       |_.eof,.ttf,etc.

I've read a little about using vhosts but the module is not already loaded in httpd.conf (commented out) and I don't want to cause a conflict with existing configuration, which I don't yet fully have my head around. I've also read about .htaccess files but AllowOverride is set to None in httpd.conf – I could change it and then start learning about .htaccess but I wonder if there's another way as I am inexperienced setting up this sort of thing.

Are there any other (easyish) ways to get apache to look for my static assets in my directory?

Best Answer

I think this is because your document root is set like this

DocumentRoot "/sharedserver.url.com"

and you want it like this:

DocumentRoot "/sharedserver.url.com/mydiv/mydept/prototypes/dist"

and the directory path must be the same as document root

<Directory "/sharedserver.url.com/mydiv/mydept/prototypes/dist">

if you do it like this and used your domain url you will be taken to index.html and your script will be shown correctly

I hope this would fix your problem