Skip to content
Ivo Yankulovski edited this page Sep 15, 2019 · 30 revisions

Localhost development

Configure hosts file if you have to /etc/hosts and add your subdomain:

127.0.0.1 localhost
127.0.0.1 my.nodewebsite.com.localhost

Open terminal in the node.js server folder

Execute node index.js and start the server.

Apache Configuration

Load or enable in your httpd file the proxy modules:

LoadModule proxy_module modules/mod_proxy.so  
LoadModule proxy_http_module modules/mod_proxy_http.so  

Add to your vhost configuration of ServerName my.nodewebsite.com.localhost the proxy line:

ProxyPass /node http://my.nodewebsite.com.localhost:8888/node  

/node is your base url, you might omit it in the node.js url
http://my.nodewebsite.com.localhost is your node.js host
8888 is your node.js listen port

Create folder node in the root of your domain and create .htaccess with the following code:

RewriteEngine On
RewriteBase /

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

AddOutputFilterByType DEFLATE can be placed in several places including root .htaccess
including your main httpd file, if you have access to it

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript

Requires deflate module enabled.

LoadModule deflate_module modules/mod_deflate.so

Sample vhost for localhost:

<VirtualHost *:80>
	ServerName my.nodewebsite.com.localhost
	ServerAlias my.nodewebsite.com.localhost
	DocumentRoot "Drive:\path\to\website"
	ProxyPass /node http://my.nodewebsite.com.localhost:8888/node
	<Directory "Drive:\path\to\website">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require local
	</Directory>
</VirtualHost>

The Apache configuration can be modified to work with NGINX server.
Caching of assets depends on all the other configurations.
Node.js works with PHP simultaneously. Logic is separated by folder.

Clone this wiki locally