Strapi server nginx automatically disconnects from domain after some time [SOLVED]

I was building a Strapi server running on stand-alone VPS using nginx.
I found out that after some hours it automatically shuts off without any error logs.

After digging and debugging for hours, I found two possible problems and one of them actually solved the issue.
 

How did I solve nginx Strapi automatically shuts off after some hours:

pm2 config:

So, I was using pm2 to run multiple node applications. However cheap VPS specially KVMs automatically restarts after some time.

When it gets restarted, the pm2 doesn't run my applications at all, I need to specify pm2 that runs applications on server restart.

This helped me, after having your scripts on pm2. just hit this command

pm2 save

This command save the app list so it will respawn after reboot.

But this was not the problem for me,

 

Vite Autorestarts:

I have coupled my server with the Frontend application which was using Vite, vite automatically restarted the server for me and made Strapi act weird if it is not set correctly.

If you have problem like this, make sure to verify your Vite config and specifically removes the server folder from vite check list.