NoMachine works out-of-the-box with headless machines. It does this by detecting that an x server is not running and creates its own. But a specific case which can lead to black screen or white screen or frozen screen on Linux is when the X server is running but it is not rendering because the video card is turned off (i.e you detach the monitor). In this case NoMachine doesn’t use its own virtual display because it detects that the X server is still running. You should therefore disable the x server first and then connect with NoMachine.
More about headless Linux hosts here: https://kb.nomachine.com/AR03P00973
To disable the X server permanently for example:
sudo systemctl set-default multi-user.target
To enable it again:
sudo systemctl set-default graphical.target
After disabling or re-enabling always restart the nx service sudo /etc/NX/nxserver --restart