I have noticed that when ever I start nginx with ubuntu command nginx
and I do systemctl status nginx
. It shows that systemctl is disabled. More over if I first start nginx with command systemctl start nginx
and I try to start nginx with command nginx
, it check the availbility of the ports and then says
nginx: [emerg] still could not bind().
So I thought there must be a difference in their purpose. When I start nginx with command nginx
the only way to stop nginx is by the means of force using killlall nginx
or kill -9 (process id)
or by clearing the port. So I am pretty sure there is some difference in them.
The difference between the examples you have provied is how the processes are being started.
Running the command nginx
will start the application and wait for your user action to stop it.
The systemctl
or service
commands are nearly the same thing and running service nginx start
or systemctl start nginx
will start a service in the background running the Nginx daemon.
You can also use this to do a service nginx restart
or systemctl restart nginx
to restart the service, or even a service nginx reload
/ systemctl reload nginx
to reload the configuration without completely stopping the Nginx server.
The reason why you can't do both nginx
and systemctl start nginx
is due to the nginx configuration already listening port 80, and you can't listen on the same port on a single IP address at the same time.
You can also force the nginx service to start on boot by running systemctl enable nginx
which will be why your systemctl status nginx
returns 'disabled'.
Hope this makes sense.