4

I have a node.js application that I had been using to server static assets. In my express server I had the following:

app.use(require('serve-static')(__dirname + '/../client'));

Which would serve files located in client/lib, client/styles, client/js

What I want to do is have Apache host all the static assets and reduce the node server to be exclusively my websocket and API server. What I am looking for are suggestions on how to properly structure my apache virtual host to accomplish something like this????

What I have so far does not work, it will get in to a request storm where once it gets all the files it tries to get all the files again but with a ?_=TIMESTAMP appended to the end of the URL:

127.0.0.1 - - [01/Sep/2015:16:42:45 -0400] "GET /components/angular/angular.min.js HTTP/1.1" 200
<LOAD THE REST OF THE FILES/>
127.0.0.1 - - [01/Sep/2015:16:42:45 -0400] "GET /components/angular/angular.min.js?_=1441140163787 HTTP/1.1" 200

Here is what I currently have:

<VirtualHost *:8080>


  DocumentRoot /path/to/static/files/client/

  # Ignore these paths as they are paths to static assets
  ProxyPass /lib !
  Alias /lib /path/to/static/files/client/lib
  ProxyPass /js !
  Alias /js /path/to/static/files/client/js
  ProxyPass /styles !
  Alias /styles /path/to/static/files/client/styles

  # Don't try to get index.html from the proxy
  ProxyPass /index.html !

  <Directory /path/to/static/files/client/>
    DirectoryIndex index.html
    Require all granted
  </Directory>
  #Options +FollowSymLinks
  #IndexIgnore */*

  RewriteEngine on

  ## From http://stackoverflow.com/questions/27526281/websockets-and-apache-proxy-how-to-configure-mod-proxy-wstunnel
  RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
  RewriteCond %{QUERY_STRING} transport=websocket    [NC]
  RewriteRule /(.*)           ws://localhost:3000/$1 [P,L]

  ProxyPass / http://localhost:3000/
  ProxyPassReverse / http://localhost:3000/

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
nathasm
  • 2,524
  • 5
  • 24
  • 35

0 Answers0