Nginx

How to Start Nginx on Linux?

Nginx is one of the most popular high-performance web servers for the modern age. It is popular for hosting high-traffic and resource-intensive applications. Pronounced as “engine-x,” it is a lightweight and highly configurable web server or a reverse proxy for other web servers.

Although Nginx is very stable and easily manageable, as a system administrator, you will encounter instances where you need to start, stop, or restart Nginx; for example, you may want to apply configuration changes or troubleshoot errors on the server.

This tutorial will discuss how to start, stop and restart the Nginx server on Linux systems using Systemd.

Pre-requisites

Before we proceed with the tutorial, it is good to ensure you have the following:

  • Ensure you have Nginx installed and configured properly
  • Have access to the root user or a sudo account.

With the above requirements met, we can begin:

What is Systemd?

Systemd is an init and service manager for Linux systems. Major Linux distributions, including Debian, Arch, REHL, and Fedora, have adopted Systemd. Systemd allows system administrators to start, stop, reload and restart services in the system. It also provides features such as logging, which is very useful in troubleshooting measures.

If you want to learn more about systemd, please consider the official documentation: https://systemd.io/

How to Manage The Nginx Service

Managing the Nginx service is quite simple, mainly because of the ease of use that Systemd gives us.

How to Start Nginx

To start the Nginx service on a Linux machine, use the command:

$ sudo systemctl start nginx.service

Assuming no encountered errors, you should see no output, and Nginx should be up and running.

Suppose you are not a system that uses init.d instead of the system; in that case, to start Nginx, use the command:

$ sudo service nginx start

How to Stop Nginx service

In this case, the reverse is true. To stop Nginx service with systemd, the command is as:

$ sudo systemctl stop nginx.service

Using init.d? use the command:

$ sudo service nginx stop

Reloading Nginx service

Nginx service also supports the reload function. This loads new configurations and restarts the worker processes using the loaded configuration. Reload feature is useful if you do not want to perform a complete reboot of the service.

To reload Nginx with systemd, use the command:

$ sudo systemctl reload nginx.service

Use the command below for init.d systems.

$ sudo service nginx reload

Restarting Nginx service

Unlike reload, restarting the Nginx service will fully stop and start the server. To restart Nginx, use the command:

$ sudo systemctl restart nginx.service

The command for SysVinit is:

$ sudo service restart nginx

Conclusion

This tutorial showed you how to manage the Nginx service on Linux systems, including those using Systemd and Init.d.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list