node.js如何处理故意大(和坏)的http请求

I'm working out on a few projects using node and each line of code that I write spans lots of ideas of how could someone destroy my node process.

Right now I'm thinking of this:

require('http').createServer(function(req, res)) {
    //DEAL WITH REQUEST HERE
  }.listen(port, net);

That's standard code for setting up a server and dealing with requests.

Let's say that I want to bring down that node process, I could send POST requests with loads of data on them and node.js would spend lots of time (and bandwith) on receiving all of them.

Is there a way to avoid this?

PHP Pros: How do you normally deal with this?

Is there a way to tell node or php (maybe apache) to just ignore requests from certain IPs ?

You can limit the http request size. Here is the middleware you can use.

https://github.com/senchalabs/connect/blob/master/lib/middleware/limit.js

http://www.senchalabs.org/connect/middleware-limit.html

P.S. Possibility duplication from maximum request lengths in node.js

For getting the IP address in node.js, you can try request.connection.remoteAddress.