I'm talking about the space between the browser window and content. I've found that it's uncomfortable to read when the text is too close to the edges and I was wondering if there is any rule that applies to this.

With regards to fluid layouts there can be issues with larger resolutions creating too much white space. This can be flipped when viewing on smaller screens where the margins become squashed (they are a percentage of the overall size). Thus it is harder to control and inevitably there will be scenarios where the lack of whitespace might impact legibility.

To mitigate this you could try for a simpler design. A design that fills the space on a big monitor could look messy on a small one. A simpler design often scales better to smaller resolutions. Many responsive designs drop content or features on smaller screens.

Controlling line length is very important for legibility and there are many methods of doing this, margins being just one of them. You can google "line length for readability" to find suggestions, research and arguments for an optimal line length, I like to limit mine to 60 characters.

Now beyond the issue of line length, margins are important for legibility but should be sacrificed when the screen is very narrow as on a phone. This becomes a balancing act - you want some margin but you don't want to reduce text line length too much.