If you get an error message like “nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)” when you restart nginx, it is because the port (here 443) is already in use by another process. In addition, nginx will not start properly.
Furthermore, if nginx does not start properly, a sock file will be generated, which may prevent it from restarting. To solve this problem, you must first delete that sock file.
Next, use the lsof command to check the ports in use in order to investigate if port collisions are the cause. For example, the command “lsof -i:80” will list the processes using port 80.
If the result shows that apache is running and causing a port conflict, stop apache. Here, the command “apachectl stop” can be used to stop apache; there is no need to kill it using the kill command.