-
Notifications
You must be signed in to change notification settings - Fork 1
HowTo
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
-
Execute node index.js and start the server.
-
create or copy
stats.jsoninindex.jsfolder -
check
modules\Subserver_stats.json -
Execute node index.js and start the subserver.
-
check
Subserverconfiguration -
Execute node example.js and start the example.
-
check
example.jsconfiguration -
configure
stats.jsonwith the right server module, you might use your own implementation -
server starts automatically, you might choose to stop it and execute different logic
-
several applications requiring the same
index.jswill load and share the samestats.jsonand therefor base server module -
one application may create several different instances on different ports depending on implementation, sharing static properties with all other servers and applications pointing to the same folder
-
Execute node application.js and start your app.
-
starting new application based on server from the same folder will throw an error
-
in each of your applications sharing server folder
closeandlistenthe http server using your own port, you might choose to load it from a separate.json -
use
htport: 0in yourstats.jsonto listen on random port, or negative integerhtport: -1to disable auto listen inindex.js -
code example:
var myport = 5000;
var protossche = require('./index.js');
protossche.serverche.htserv.close().listen(myport);
- set
https: trueinstats.json - place
key.pemandcert.pemin your server folder ofindex.js - or specify
httpsopObject instats.jsonfor any additional Node server configuration based on official documentation - special https options keys:
keyPath,certPath,pfxPath,caPath
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
Enable HTTP/2, if you need it locally, node will leverage the protocol:
LoadModule proxy_http2_module modules/mod_proxy_http2.so
LoadModule http2_module modules/mod_http2.so
ProtocolsHonorOrder On
Protocols h2 http/1.1
Enable SSL, if you need it locally, and configure the server keys:
LoadModule ssl_module modules/mod_ssl.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 url
http://my.nodewebsite.com.localhost is your node host, use raw http for performance instead of https, ssl can be enforced from the next server layer of Apache/NGINX
8888 is your node listen port
GZIP transfer is enabled per header content-type and requires deflate module.
LoadModule deflate_module modules/mod_deflate.so
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 text/javascript
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 application/json
AddOutputFilterByType DEFLATE can exist in several places including root .htaccess
or main httpd file, if you have access to it
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript application/json
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.