Unfortunately, I can't get rid of exec call because the whole idea is that start.cgi is a client programm which must check if server is running and start it if it's not. I can't get rid of location also because start.cgi must then redirect client to a page which will connect to the server via sockets.
Then you should not use exec to run the server but rather system. With exec the server will keep the socket to the client open. And probably die with SIGPIPE when the client closes it.
Update: Or you can close the pipe explicitely in the server code.
I believe you should fork the server before using the exec function.