The way many modules are written for D&D, exploration spaces and dungeon-crawl spaces are built with the idea of defensible positions in mind; the most common examples are small rooms with only one entrance that, in raw mechanical design terms, serve no actual purpose beyond being a location that the party could in theory use to bed down and get rest they need, in a pinch. It's not usually safe, but it's easier to disguise your presence and set a quiet watch and buy the eight hours you need.

In video game translations, this is like having small zones within your dungeon-crawl space or exploration terrain that are demarcated as being 'rest possible'; the players are notified about it when discovering such defensible locations.

This works quite well for limiting long resting, without actually restricting it, because most players will choose to push on through their resources until they feel they need to, and seek out or back track to one of these resting points only when they feel it's worthwhile to do so. What counts as worthwhile will be different for each player, or course - an ideal system leaves that determination up to the players.

Such a space isn't necessarily safe; just safer, and easier to respond to if danger finds you. The potential for random encounters can exist here, as they happen upon your camp; most random encounters of this sort would be balanced to be only moderately challenging to a party operating on minimal resources, have a chance of happening when you begin to rest, be limited to one per rest, and after dealing with one your rest completes and you get your refresh of everything, as though no encounter had occurred.

The worry about being attacked while at your weakest is legitimate, sure, but it also has an easy solution; most player will not push until they are falling over dead before resting, if their only option for rest bears a risk of danger thanks to their location. It's a system that self regulates, to a certain extent, without actually restricting players because the ones who still do want to long rest after each encounter still can, if they don't mind seeking out one of these safe spots between every encounter on their crawl - and even if they are interrupted, they can happily burn everything to nuke the interruption, because they know they'll get a full refresh after it's done. A watch character (or characters) could give the party the opportunity to have the upper hand (or not, and to be caught off guard) - and upon noticing the danger, the opportunity to strike first, threaten off, or try to avoid detection, etc.,

Having the main camp act as a larger scale home base - or rather, that is, having a larger, fixed home base location that is a world-anchored location, per act of the game - can work in tandem with this, as the space where major interpersonal events and other important occurrences can happen, while temporary camps in dangerous spaces can be a place for snippets of banter and dialogue that fleshes out characters and gives them more presence, without being necessary or important to their story.

I'm fairly sure everything I've said here has been suggested by others in other threads already, but I just wanted to add my opinion on the solution - I wouldn't agree with limiting the number of rests that will be uneventful by level; that would get impractical quickly, and would lose its meaning before long... but I would support there being some kind of under-the-hood mercy flag that increases your odds of an uninterrupted rest whenever your rest is interrupted.