Reverse proxy server usign Node.js.
Before starting the server, there are a few steps you need to complete.
1️⃣ Setup .env file:
SSL_KEY="PATH/TO/SSL_KEY"
SSL_CERT="PATH/TO/SSL_CERTIFICATE"
2️⃣ Setup list.json file:
[
{
"name": "",
"protocol": "",
"port": 8000,
"host": [ "HOSTNAME" ],
"forward": {
"address": "HOSTNAME",
"port": 8000
}
},
]name(optional): Before starting the server, there are a few steps you need to complete.protocol: Canbahttp,httpsortcp.port: The port on which the reverse proxy listens.host: An array of hostnames that the proxy should handle.forward: The destination server details.
Example:
[
{
"name": "Chat Server",
"protocol": "tcp",
"port": 8000,
"host": [ "your.domain.com", "www.domain.com", "my.domain.com" ],
"forward": {
"address": "your-server.local",
"port": 3000
}
},
{
"protocol": "https",
"port": 8001,
"host": [ "domain.com" ],
"forward": {
"address": "your-web-server.local",
"port": 3000
}
},
{
"protocol": "tcp",
"port": 8002,
"host": "*",
"forward": {
"address": "your-web-db.local",
"port": 3000
}
}
]Explaination:
- Requests to
your.domain.com:8000,www.domain.com:8000, ormy.domain.com:8000will be forwarded toyour-server.local:3000over TCP. - Requests to
domain.com:8001over HTTPS will be forwarded toyour-web-server.local:3000over HTTP. - Requests to every doamin in port
:8002will be forwarded toyour-web-db.local:3000over TCP.
After cloning this project, follow these steps:
1️⃣ Navigate to the project directory:
cd reverse-proxy2️⃣ Install dependencies:
npm install3️⃣ Start the server:
npm start