SoFunction
Updated on 2025-03-01

Detailed explanation of the command to set up the Nginx service on Linux

1. Preparation

Note: Prepare to build nginx machine

2. Operation steps

2.1 Create a boot script first

Note: Use root user to execute! ! !

cd /etc/systemd/system

vim 
# Only modify the path /usr/local/nginx/sbin/nginx (modify it to your nginx path)
[Unit]
Description=nginx service
After=

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=

2.2 Set file permissions

cd /etc/systemd/system

chmod 755 

2.3 Set up the power-on self-start

systemctl daemon-reload

systemctl enable nginx

2.4 Verification

# nginx startupsystemctl start nginx 

# nginx stopsystemctl stop nginx 

#Just restart the server directly (nginx will automatically restart)reboot	

2.5 Common Commands

# Start nginx servicesystemctl start 

# Restart nginx servicesystemctl restart 

# Check the current status of nginx servicesystemctl status 

# Stop the startup and startsystemctl disable 

Summarize

This is the article about the detailed explanation of the command to set up the boot self-start command under Linux. For more related content on Linux Nginx boot, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!