-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the cluster-static-server
wiki!
- Clone or Download this repo.
- Extract it.
- Go to the extracted directory.
- Run
$ npm install
. - Done
- To start master server
$ npm run master
or$ node server-master.js
. - To start node server
$ npm run node
or$ node server-node.js
.
Note :
- You are able to start master and node server in same machine server with different port. But, actualy Master and Node server should be on different machine server so you will get the best performance.
This cluster static server is working under HTTP for communicate with all nodes server.
-
MASTER
Master server is for proxy to all nodes and management file through API. -
NODE
Node server is for storage file and serving the static file for public. -
Static File
Your public file is located atNode 1 http://localhost:3000/ns1/2020/01/09/lgsfdkjhasdufgsdf.png Node 2 http://localhost:3000/ns2/2020/01/09/jhkuwuerkfndskhsk.png
Actualy your nodes is serving your file to public but the url file is proxied by master server.
See at/ns1/
and/ns2/
above.
Assume you have already 3 machine server.
- Master is on 10.0.0.11:3000
- Node 1 is on 10.0.0.12:3001 >> give it prefix name with
/ns1
- Node 2 is on 10.0.0.13:3002 >> give it prefix name with
/ns2
Because static server is for public use, so you have to set domain name for Master server.
10.0.0.11 >> static.yourdomain.com
10.0.0.12 >> no need to have a domain
10.0.0.13 >> no need to have a domain
See example configuration based case above.
// all this config is required
const config_master = {
// x_token header authentication for master API
x_token: '12345678',
// x_token header authentication for node API
node_x_token: '87654321',
// set origin for master server
// Origin is the full base url of master server.
// You can change this origin with domain name like http://yourdomain.com
origin: 'http://static.yourdomain.com', // without trailing slash
// set this master server port
masterPort: 3000,
// node server list
nodeServer: [ // you can add more node server
{ upstream:'http://10.0.0.12:3001', prefix:'/ns1', http2: false },
{ upstream:'http://10.0.0.13:3002', prefix:'/ns2', http2: false }
],
// Limit upload size
limitSize: (50 * 1024 * 1024), // 50Mb
// Block upload to spesific node destination.
blockNode: [], // Ex. ['/ns2','/ns3'] means the file will not upload to /n2 and /ns3.
// Print the log
logger: true
}
module.exports = config_master;
Remember that Node 1 prefix name is /ns1
and Node 2 prefix name is /ns2
. So you only have to set nodePrefixName
in config-node.js
. And check for the nodePort
.
Example for Node 1:
// set node prefix name for this node server
nodePrefixName: '/ns1', // without trailing slash but leading slash is required
// set node port for this node server
nodePort: 3001,
Example for Node 2:
// set node prefix name for this node server
nodePrefixName: '/ns2', // without trailing slash but leading slash is required
// set node port for this node server
nodePort: 3002,
We include the postman.json
file in this source for an example how to use API. Just import it to your postman application and then you can learn from it.
Note :
- Upload and Delete must be using API from master server because API for node server is for development only.
-
Can't send request to node server
- Before you add your node server upstream into
config-master.js
in master server, make sure you have already testhttp://YOUR_IP_NODE:PORT/status
is accessed for public. - Better to use IP address for all node server, because using domain sometimes slower caused by DNS resolve time.
- Before you add your node server upstream into
-
Can't pass request header in NGINX
If you can't pass the request header in NGINX, you need to add this line below in your nginx.conf
underscores_in_headers on;
This cluster-static-server project was design for flexible to use or to fork. Also I want to keep this project always minimalis, so there is bit limitations in this project :
-
No Complex Authentication
I did not implement any complex authentication in this project because I want you to be more flexible to choose any kind of authentication method for your business application. Actualy for simple authentication by header is already implemented in this project. Just improve it by yourself so it can be suitable to your business application. -
No Update File
Naturaly a static server will serve "as it" file to your browser with long cache expiring time. So update file feature could be useless for static server. But you can create your own application to manage your file with this cluster-static-server API.
This project is ready for Production, I've use this cluster-static-server
in big cloud microservices infrastructure with kubernetes.
I'm as the author of this project will help you for:
- Adding secure authentication with Basic Auth, Session or JWT?
- Configure Reverse Proxy with NGINX?
- Solving your server problem?
Just buy me coffee
Bitcoin Wallet: 1MtPkZmYEBtQz3odhubB1XpJXyHpV15dYj
Then let me know via Whatsapp : +628192222254