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
,https
ortcp
.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:8000
will be forwarded toyour-server.local:3000
over TCP. - Requests to
domain.com:8001
over HTTPS will be forwarded toyour-web-server.local:3000
over HTTP. - Requests to every doamin in port
:8002
will be forwarded toyour-web-db.local:3000
over TCP.
After cloning this project, follow these steps:
1️⃣ Navigate to the project directory:
cd reverse-proxy
2️⃣ Install dependencies:
npm install
3️⃣ Start the server:
npm start