Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to start and shut down Nginx under Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to start and close Nginx under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Nginx is a performance-oriented HTTP server, which has the advantages of less memory and high stability compared with Apache and lighttpd.

Prerequisites:

Install and configure a system with Nginx

Access terminal window or command line

User account with sudo or root privileges

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

Using systemctl to start, stop and restart Nginx

1. How to view the status of the Nginx server

Nginx runs on your server as a service. This means that it should be active 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:

The sudo systemctl status nginx system switches to state mode, displaying a great deal of information about the Nginx service.

If the service is running (active), the third line shows the green active (running) status.

If Nginx is not running, it will be displayed as inactive in standard white.

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

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 and Debian 9). The SystemD manager runs through the systemctl command.

This systemctl command is the basic Linux command. This means that it can be used for 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

To start Nginx, ask systemctl to execute the command using the following start options:

Sudo systemctl start nginx

2. How to restart Nginx

1), Nginx restart

If you want to refresh the Nginx after changing the configuration, it is best to reload the service. This closes the old process and restarts the new process with the new configuration.

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

Sudo systemctl reload nginx Note: if the Nginx service is not activated, the Nginx cannot be reloaded.

2), Nginx forced restart

For major configuration changes, you can force a full restart of Nginx. This forces the entire service and subprocess to be shut down, and then restarts the entire package.

Enter the following command:

Sudo systemctl restart nginx3), restart vs and reload Nginx

This reload command keeps the Nginx server running when the updated configuration file is reloaded. If Nginx finds a syntax error in any configuration file, the reload will abort and the server will continue to run based on the old configuration file. Reloading is safer than restarting Nginx.

The restart command shuts down the server (including all related services) and powers it back on. Restart Nginx only if you make a major configuration update, such as changing a port or interface. This command forces all worker processes to be shut down.

Start, stop and reload Nginx using the Nginx command

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

1. Start Nginx

To start Nginx and related processes, enter the following:

If sudo / etc/init.d/nginx start runs successfully, the terminal output displays the following:

Output [ok] Starting nginx (via systemctl): nginx.service.2, Nginx restart

Force shut down and restart Nginx and related processes:

Sudo / etc/init.d/nginx restart

Alternatively, use the following nginx-s command:

Sudo nginx-s restart3, Nginx stop

To disable or stop the Nginx service, enter the following:

Sudo / etc/init.d/nginx stop

Or, use:

Sudo nginx-s stop4, Nginx reload

To stop and restart Nginx and related processes normally, use the following command:

Sudo / etc/init.d/nginx reload

Alternatively, you can use the nginx-s command to pass instructions directly to Nginx:

Sudo nginx-s reload5, Nginx exit

Force the shutdown of the Nginx service by using the quit directive and the nginx-s command:

Sudo nginx-s quit above is all the contents of this article "how to start and shut down Nginx under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report