Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:nodejs_setup [2014/07/30 18:05]
Michael Armstrong [Install Node.js]
litespeed_wiki:nodejs_setup [2015/07/28 21:28]
Michael Alegre removed
Line 3: Line 3:
 Node.js is a platform that generally runs as a separate web server. LiteSpeed Web Server can be configured to proxy traffic to Node.js so that users can run Node.js applications (like Ghost) on their sites. Node.js is a platform that generally runs as a separate web server. LiteSpeed Web Server can be configured to proxy traffic to Node.js so that users can run Node.js applications (like Ghost) on their sites.
  
-The following wiki guides you through the steps to set up Node.js with LiteSpeed Web Server. The wiki assumes that you have a functional LSWS installation running off of Apache configurations (though the steps can be easily adapted to using LSWS native configuration files).+The following wiki guides you through the steps to set up Node.js with LiteSpeed Web Server. The wiki assumes that you have a functional LSWS installation running off of Apache configurations (though the steps can be easily adapted to using LSWS-native configuration files).
  
 ===== Install Node.js ===== ===== Install Node.js =====
Line 15: Line 15:
   tar xvzf node-latest.tar.gz   tar xvzf node-latest.tar.gz
  
-Build Node.js from the tarball.+Build Node.js from the source.
   ​   ​
   cd node-vX.X.X   cd node-vX.X.X
Line 21: Line 21:
   make   make
   make install   make install
 +
 +===== Add Your Node.js Application =====
 +
 +For the rest of this wiki, we will be using the example Node.js web server ''​example.js''​ found on [[http://​nodejs.org/​|Node.js'​s homepage]]. This web server runs on port 1337 and responds with "Hello World" to every request.
  
 ===== Proxy Node.js Traffic ===== ===== Proxy Node.js Traffic =====
  
-Now that Node.js is installed on your server, you will need to tell LSWS to send the proper traffic to Node.js. Starting with LSWS 4.2.13, this can be done with a just a rewrite rule (if Node.js is installed on the same server as LSWS). Simply add a rewrite rule that will redirect traffic to the port Node.js is listening on. The following is an example:+Now that Node.js is installed on your server, you will need to tell LSWS to send the proper traffic to your Node.js ​application. Starting with LSWS 4.2.13, this can be done with a just a rewrite rule (if Node.js is installed on the same server as LSWS). Simply add a rewrite rule that will redirect traffic to the port Node.js is listening on. The following is an example, the domain name for the site is "​example.com",​ Node.js application server is running on port 1337, add the following rewrite rule to .htaccess under document root directory. ​
  
   RewriteEngine On   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-f   RewriteCond %{REQUEST_FILENAME} !-f
-  ​RewriteCond %{REQUEST_FILENAME} !-d +  RewriteRule ^(.*)$ http://example.com:1337/$1 [P,L]
-  ​RewriteRule ^(.*)$ http://ghost.domain.com:XXXXX/ghost/$1 [P,L]+
  
-The above example redirects all traffic (after checking that it is a directory or file) to a Ghost subdomain using port XXXXX. Port XXXXX should be the port Node.js is running ​on.+The above example redirects all traffic (after checking that it is a directory or file) to port 1337 (where ''​example.js'' ​is running, as noted above). Static files are still served by LSWS.  
 + 
 +If there is no need to serve static files through LSWS, you can let LSWS proxy all requests to backend application server with rewrite rule 
 + 
 +  RewriteEngine On 
 +  RewriteRule ^(.*)$ http://​example.com:1337/$1 [P,L]
  
 ==== If Using LSWS Below 4.2.13 or Proxying to an External Server ==== ==== If Using LSWS Below 4.2.13 or Proxying to an External Server ====
Line 45: Line 53:
 === Configure the Web Server External Application === === Configure the Web Server External Application ===
  
-{{litespeed_wiki:​create_proxy_extapp.png?700}}+{{litespeed_wiki:​config_proxy_extapp.png?700}}
  
-In the above configurations we have made the Location 1.2.3.4:50000. It is important that the Location match the IP (127.0.0.1 if it is on the same server) and port Node.js is running on.+In the above configurations we have made the Location 1.2.3.4:1337. It is important that the Location match the IP (127.0.0.1 if it is on the same server) and port your Node.js ​application ​is running on.
  
-After saving the configurations,​ restart LSWS to save changes. Your traffic should be redirected to Node.js now.+After saving the configurations,​ restart LSWS to save changes. Your traffic should be redirected to your Node.js ​application ​now.
  
 ===== Notes ===== ===== Notes =====
  
   * If you encounter errors using Node.js, please make sure that Node.js is started and running when using it.   * If you encounter errors using Node.js, please make sure that Node.js is started and running when using it.