简体   繁体   English

需要外部防火墙的 NodeJS TLS/TCP 服务器

[英]NodeJS TLS/TCP server in need of an external firewall

Problem: I have an AWS EC2 instance running FreeBSD.问题:我有一个运行 FreeBSD 的 AWS EC2 实例。 In there, I'm running a NodeJS TLS/TCP server.在那里,我正在运行 NodeJS TLS/TCP 服务器。 I'd like to create a set of rules (in my NodeJS application) to be able to individually block IP addresses programmatically based on a few logical conditions.我想创建一组规则(在我的 NodeJS 应用程序中),以便能够根据一些逻辑条件以编程方式单独阻止 IP 地址。

I'd like to run an external (not on the same machine/instance) firewall or load-balancer, that I can control from NodeJS programmatically, such that when certain conditions are given, I can block a specific remote-address(IP) before it reaches the NodeJS instance.我想运行一个外部(不在同一台机器/实例上)防火墙或负载平衡器,我可以通过 NodeJS 以编程方式控制,这样在给定条件时,我可以阻止特定的远程地址(IP)在它到达 NodeJS 实例之前。

Things I've tried: I have initially looked into nginx as an option, running it on a second instance, and placing my NodeJS server behind it, but after skimming through the NGINX Cookbook Advanced Recipes for High Performance Load Balancing I've learned that only the NGINX Plus (the paid version) allows for remote/API control & customization.我尝试过的事情:我最初将nginx作为一种选择,在第二个实例上运行它,并将我的 NodeJS 服务器放在它后面,但是在浏览了NGINX Cookbook Advanced Recipes for High Performance Load Balancing 之后,我了解到只有 NGINX Plus(付费版本)允许远程/API 控制和定制。 While I believe that paying $3500/license is not too much (considering all NGINX Plus' features), I simply can not afford to buy it at this point in time;虽然我认为支付 3500 美元/许可证并不算太多(考虑到 NGINX Plus 的所有功能),但我现在根本买不起; in addition the only feature I'd be using (at this point) would be the remote API control and the IP address blocking .此外,我将使用的唯一功能(此时)是远程 API 控制IP 地址阻塞

My second thought was to go with the AWS/ELB (elastic-load-balancer) by integrating AWS' SDK into my project.我的第二个想法是通过将 AWS 的 SDK 集成到我的项目中来使用 AWS/ELB(弹性负载平衡器)。 That sounded feasible, unfortunately, after reading a few forum threads and part of their documentation (unless I'm mistaken) it seems these two features I need are not available on the AWS/ELB.这听起来可行,不幸的是,在阅读了一些论坛主题和他们的部分文档后(除非我弄错了),我需要的这两个功能似乎在 AWS/ELB 上不可用。 AWS seems to offer an entire different service called WAF that I honestly don't understand very well (both as a service and from a feature-stand-point). AWS 似乎提供了一种完全不同的服务,称为 WAF,老实说,我不太了解它(无论是作为服务还是从功能的角度来看)。

I have also (briefly) looked into CloudFlare, as it was recommended in one of the posts, here on Sackoverflow, though I can't really tell if their firewall would allow this level of (remote) control.我还(简要地)研究了 CloudFlare,正如 Sackoverflow 上的其中一篇文章中所推荐的那样,尽管我无法确定他们的防火墙是否允许这种级别的(远程)控制。

Question: What are my options?问题:我有哪些选择? What would you guys recommend I did?你们会推荐我做什么?

I think Nginx provide such kind of functionality please refer to link If you want to block an IP with Node TCP you can just edit a nginx config file and deny IP address.我认为 Nginx 提供了这种功能,请参阅链接如果您想使用 Node TCP 阻止 IP,您只需编辑 nginx 配置文件并拒绝 IP 地址。

Frankly speaking, If I were you, I would use AWS WAF but if you don't want to use it, you can simply use Node JS坦率地说,如果我是你,我会使用 AWS WAF 但如果你不想使用它,你可以简单地使用 Node JS

In Node JS You should have a global array variable where you will store all blocked IP addresses and upon connection, you will check whether connected host IP is in blocked IP variable.在 Node JS 中,您应该有一个全局数组变量,您将在其中存储所有被阻止的 IP 地址,并且在连接时,您将检查连接的主机 IP 是否在被阻止的 IP 变量中。 However there occurs a problem when machine or application is restarted, you will lose all information about blocked IP-s.然而,当机器或应用程序重新启动时会出现问题,您将丢失有关被阻止 IP-s 的所有信息。 So as a solution to that you can just setup Redis (It is key-value database but there are also other datatypes) DB and store blocked IP-s there.因此,作为解决方案,您可以只设置Redis (它是键值数据库,但也有其他数据类型)DB 并在那里存储被阻止的 IP。 Inasmuch as Redis DB is in RAM all interaction with DB will be instantly and as long as machine or node is restarted, Redis makes a backup on hard drive and it syncs from it and continue to work in RAM with old databases.由于 Redis DB 在 RAM 中,所有与 DB 的交互都会立即发生,只要机器或节点重新启动,Redis 就会在硬盘上进行备份,并从中同步并继续在 RAM 中使用旧数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM