Apache为node.js提供静态文件

时间:2015-09-02 00:29:37

标签: node.js apache

我有一个node.js应用程序,我一直用它来服务静态资产。在我的快递服务器中,我有以下内容:

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

将提供位于客户端/ lib,客户端/样式,客户端/ js

中的文件

我想要做的是让Apache托管所有静态资产,并将节点服务器减少为我的websocket和API服务器。我正在寻找的是关于如何正确构建我的apache虚拟主机来完成这样的事情的建议????

到目前为止我没有工作,它将进入一个请求风暴,一旦它获得所有文件它尝试再次获取所有文件,但在URL的末尾附加?_ = TIMESTAMP:

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

以下是我目前的情况:

<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>

0 个答案:

没有答案