Project

General

Profile

Support #356

Updated by Daniel Curtis over 10 years ago

Lets say that you want to experiment with Node.js or you want to start to leverage its awesome features but you don’t want to throw away all of your existing Apache compatible website. This tutorial will show you how to configure your existing Apache server to forward requests for a specific folder to Node.js. I’m going to set it up so Node.js handles the /node/ folder and Apache handles everything else. 

 h3. Assumptions and My Setup 

 # Apache server running on port 80 
 # Node.js server already running on port 3000 8080 
 # Debian Wheezy 7 
 # The site is example.com 

 h2. Configure the Proxy 

 Enable the modproxy and modproxyhtml Apache modules. They should be available by default so just enable them with the a2enmod command. 
 <pre> 
 sudo a2enmod proxy 
 sudo a2enmod proxy_http 
 </pre> 

 Now edit your virtual host file (@/etc/apache2/sites-available/example.com.conf@) to have reverse proxy settings. Within the node, add the following: 
 > ServerName example.com 
 > ServerAlias www.example.com 
 > ProxyRequests off 
 >  
 > <Proxy *> 
 > Order deny,allow 
 > Allow from all 
 > </Proxy> 
 > 
 > <Location /> 
 > ProxyPass http://node.example.com:3000/ http://localhost:3000/ 
 > ProxyPassReverse http://node.example.com:3000/ http://localhost:3000/ 
 > </Location> 

 Save that and restart apache with: 
 <pre> 
 sudo service apache2 restart 
 </pre> 

 h2. Resources 

 * http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache

Back