Remote Xdebug and 504 on lost connection

I set up a remote Xdebug to work through the SSH tunnel. Everything works perfectly, but if I eventually drop the SSH connection (lost internet connection, switch VPNs or just close the laptop screen) my remote website drops into 504 error. Restarting nginx and php-fpm doesn’t help. The website simply wakes up on its own after 15-20 min.

Seems that there is a kind of timeout somewhere? Can you help where? And what can I do to prevent the site dropping into 504?

php.ini:

zend_extension=xdebug
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9093
xdebug.start_with_request=yes
xdebug.remote_handler = dbgp
xdebug.idekey=PHPSTORM

(yes, I use port 9093 for Xdebug and it works)

To create SSH tunnel I use putty:

enter image description here