• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

Nginx Basics: From Nginx Restart To Configuration Checks

CJ Saathoff

Published on: April 11, 2024

Categories: Linux Command Line 0

Nginx (pronounced as “engine-x”) is a popular web server and reverse proxy server. The Nginx web server has multiple versions, though this guide focuses on the open-source version. This post will look into how to manage Nginx using the systemctl command on a traditional install and the case of a cPanel installation, focused from a command line perspective.

Table of Contents
  • Managing Nginx Using Systemctl On A Standard Install
    • Confirming That Nginx Is Installed?
    • Start, Enable, And Restart Nginx
    • Extra: Automatically Restart Nginx Using Systemctl
  • Managing Ngnix With Reverse Proxy On Cpanel
    • How Do I Know My Server Is Using Cpanel?
    • Restarting Ngnix On Cpanel
  • Checking Configuration files
  • Conclusion
  • Resources

Managing Nginx Using Systemctl On A Standard Install

This section covers how to confirm that Nginx is installed, starting, stopping, restarting as well as how to restart the service on failure.

Confirming That Nginx Is Installed?

First, to confirm that Nginx is installed, use the following command.

type -p nginx

Start, Enable, And Restart Nginx

With these are all though systemctl commands replace the second word in the command with the action we want. See the following commands:

To enable Nginx to start on boot

sudo systemctl enable nginx

To start Nginx a single time:

sudo systemctl start nginx

After making changing or adding new configuration use, the following to reload Nginx:

sudo systemctl reload nginx

To restart the Nginx server:

sudo systemctl restart nginx

Extra: Automatically Restart Nginx Using Systemctl

For public-facing web servers, you may want to have your web server restart on failure to minimize potential downtime caused by such an issue. Though this is not fix to what caused the service to fail, this will give you a bit more time to do a thorough investigation.

We can do this by editing the systemd unit file.

First, confirm the location of the unit file using the below command

systemctl status nginx | grep "Loaded"

On my test server, the file is located at /usr/lib/systemd/system/nginx.service

We will add the following two lines using your preferred text editor make sure to use sudo or root privileges.

Restart=on-failure
RestartSec=3s

So the file will look something like this

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
LimitNOFILE=8192
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
# Added to restart on failure
Restart=on-failure
RestartSec=3s

[Install]
WantedBy=multi-user.target

Save and close out of the file.

Then run the following command, so systemd reloads the changes:

sudo systemctl daemon-reload

Managing Ngnix With Reverse Proxy On Cpanel

This section covers working with the Ngnix proxy provided by cPanel the package called ea-nginx. At the time of writing this is the only method (which is non experimental) that cPanel supports.

Note: These tasks require root user account access.

How Do I Know My Server Is Using Cpanel?

The command below will check for /usr/local/cpanel/cpanel as this will only exist on cPanel servers.

if [ -x /usr/local/cpanel/cpanel ]; then
    echo "cPanel is installed on this server."
else
    echo "cPanel is not installed on this server."
fi

If you aren’t sure if Nginx is installed you can check using the following command:

yum list installed ea-nginx

If the command returns results then that confirms that ea-nginx (“NGINX with Reverse Proxy”) is installed.

Restarting Ngnix On Cpanel

To restart services in cPanel use the cPanel provided restart scripts, as they interact with chkservd (cPanel’s service watchdog).

The command would be:

/usr/local/cpanel/scripts/restartsrv_nginx

If Nginx is installed and the above command does not bring Nginx online, the next step is to ensure it isn’t disabled. The WHM API command below enables the service and monitoring.

whmapi1 configureservice service=nginx enabled=1 monitored=1

If both the above fail, you can try to reinstall ea-nginx.

yum reinstall ea-nginx

If you have any additional issues please refer to the official docs.

Checking Configuration files

To Check the configuration files for a syntax error use the following command:

nginx -t

If the command returns that the syntax is ok and the test was successful, then everything is good.

If there is an issue it will point you to the configuration file that is causing it so you can investigate the configuration file further.

Conclusion

In this post, we have discussed that Nginx has multiple versions and that this post concerns the open-source version. From there split off into a cPanel and traditional installation section which goes over how to check that Nginx is installed and basic service management from restart and end on how to check the configuration syntax.

Resources

  • https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
  • https://docs.cpanel.net/knowledge-base/web-services/nginx-with-reverse-proxy/
CJ Saathoff

Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.

Related Posts

Systemd Service File Example – How it Works

The service file manager in Linux - systemd - is configured using something called "unit files". Here's an example, and how it works.

Symbolic Links vs Hard Links in Linux

Linux offers various methods for referencing files and directories through other files and directories, without creating copies of the original. If you have color coding enabled in your bash terminal, you might have seen some folders full of files of a different color from regular files. There’s a good chance that these are all symbolic […]

Bash Debug Mode: set -x and the PS4 Variable

When coding a program, you usually have a full IDE set up with autocomplete and stack tracing, allowing you to pause execution at any point and see what’s going on under the hood. These tools make coding more productive, and they’ve been in use for a long time. But what if you’re just quickly coding […]

All About Bash Parameter Expansion

Parameter expansion in bash is very useful when working with strings like filenames and log entries. It allows you to clean up text.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA