Home Operation and Maintenance Nginx How to start and shut down Nginx under Linux

How to start and shut down Nginx under Linux

May 24, 2023 pm 11:04 PM
linux nginx

Nginx is an HTTP server designed for performance. Compared with Apache and lighttpd, it has the advantages of less memory and high stability.

How to start and shut down Nginx under Linux

Prerequisites:

System with Nginx installed and configured

Access to a terminal window or command line

User account with sudo or root privileges

Existing SSH connection to the remote system (if you are working remotely)

1. Use systemctl to start, stop And restart Nginx

1. How to check the status of Nginx server

Nginx runs as a service on your server. This means it should be actively running in the background, even if you can't see anything on the screen. You can display the status of the Nginx service by entering the following command in the terminal window:

 sudo systemctl status nginx
Copy after login

The system will switch to status mode, displaying a large amount of information about the Nginx service.

If the service is running (active), the third line will show a green active (running) status.

If Nginx is not running, it will appear inactive in standard white.

If something goes wrong and Nginx fails to load, you will see a red status Failed with some information related to the failure.

How to start and shut down Nginx under Linux

Press q to reactivate the bash prompt.

SystemD is the default service manager on modern Linux distributions (Ubuntu 20.04/18.04/16.04, CentOS 7/7 and Debian 9/10). The SystemD manager is run via the systemctl command.

The systemctl command is a basic Linux command. This means it can be used with any Linux service.

2. Stop and start Nginx

systemctl can be used to start and stop the Nginx service.

To stop Nginx, run the following command:

 sudo systemctl stop nginx
Copy after login

How to start and shut down Nginx under Linux

To start Nginx, execute the systemctl command with the following start option:

 sudo systemctl start nginx
Copy after login

How to start and shut down Nginx under Linux

2. How to restart Nginx

1), Nginx restart

If you want to restart Nginx after changing the configuration Refresh Nginx and preferably reload the service. This will shut down the old process and restart the new process with the new configuration.

Use the systemctlLinux command to reload the Nginx service. Run the following command:

 sudo systemctl reload nginx
Copy after login

Note: Nginx cannot be reloaded if the Nginx service is not activated.

2), Nginx force restart

For major configuration changes, you can force a complete restart of Nginx. This will force a shutdown of the entire service and subprocesses, then restart the entire package.

Enter the following command:

 sudo systemctl restart nginx
Copy after login

3), restart vs reload Nginx

The reload command is used when reloading the updated configuration file The Nginx server remains running. If Nginx finds a syntax error in any configuration file, the reload will be aborted and the server will continue running based on the old configuration file. Reloading is safer than restarting Nginx.

The restart command will shut down the server (including all related services) and turn the power back on. Only restart Nginx when making major configuration updates, such as changing ports or interfaces. This command will forcefully shut down all worker processes.

2. Start, stop and reload Nginx using Nginx commands

Nginx has a set of built-in tools to manage services that can be accessed using Nginx commands.

1. Nginx start

To start Nginx and related processes, please enter the following:

 sudo /etc/init.d/nginx start
Copy after login

If the operation is successful, the terminal output will display the following Content:

 Output
 [ ok ] Starting nginx (via systemctl): nginx.service.
Copy after login

2. Nginx restart

Force shutdown and restart Nginx and related processes:

 sudo /etc/init.d/nginx restart
Copy after login

How to start and shut down Nginx under Linux

或者,使用以下nginx -s命令:

sudo nginx -s restart
Copy after login

3、Nginx停止

要禁用或停止Nginx服务,请输入以下内容:

sudo /etc/init.d/nginx stop
Copy after login

How to start and shut down Nginx under Linux

或者,使用:

sudo nginx -s stop
Copy after login

4、Nginx重新加载

要正常停止并重新启动Nginx和相关进程,请使用以下命令:

sudo /etc/init.d/nginx reload
Copy after login

How to start and shut down Nginx under Linux

或者,您可以使用nginx -s命令将指令直接传递给Nginx:

sudo nginx -s reload
Copy after login

5、Nginx退出

通过使用quit指令与nginx -s命令来强制关闭Nginx服务:

sudo nginx -s quit
Copy after login

The above is the detailed content of How to start and shut down Nginx under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

See all articles