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 solve the problem of Nginx boot self-startup in Centos7

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to solve the problem of Nginx boot self-startup in Centos7". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

We can solve the problem of setting nginx boot self-startup in centos7 by writing a boot self-startup shell script.

Test environment

Operating system: centos7 64-bit 1611

Nginx version: 1.11.10

Configuration parameters during native nginx installation

. / configure\-- prefix=/usr/local/nginx\-- pid-path=/usr/local/nginx/logs/nginx.pid\-- lock-path=/var/lock/nginx.lock\-- error-log-path=/var/log/nginx/error.log\-- http-log-path=/var/log/nginx/access.log\-- with-http_gzip_static_module\-- http-client-body-temp-path=/var/temp/nginx/client\-- http-proxy- Temp-path=/var/temp/nginx/proxy\-http-fastcgi-temp-path=/var/temp/nginx/fastcgi\-http-uwsgi-temp-path=/var/temp/nginx/uwsgi\-http-scgi-temp-path=/var/temp/nginx/scgi

Write a script

[root@localhost] # vim / etc/init.d/nginx

Here is the content of the script

#! / bin/bash# nginx startup script for the nginx http server# it is v.0.0.2 version.# chkconfig:-85 "description: nginx is a high-performance web and proxy server.# it has a lot of features But it's not for everyone.# processname: nginx# pidfile: / usr/local/nginx/logs/nginx.pid# config: / usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx/logs/nginx.pidretval=0prog= "nginx" # source function library.. / etc/rc.d/init.d/functions# source networking configuration.. / etc/sysconfig/network# check that networking is up. ["${networking}" = "no"] & & exit 0 [- x $nginxd] | | exit nginx_pid start nginx daemons functions.start () {if [- e $nginx_pid]; then echo "nginx already running...." Exit 1fi echo-n $"starting $prog:" daemon $nginxd-c ${nginx_config} retval=$? Echo [$retval= 0] & & touch / var/lock/subsys/nginx return $retval} # stop nginx daemons functions.stop () {echo-n $"stopping $prog:" killproc $nginxd retval=$? Echo [$retval= 0] & & rm-f / var/lock/subsys/nginx / usr/local/nginx/logs/nginx.pid} # reload nginx service functions.reload () {echo-n $"reloading $prog:" # kill-hup `cat ${nginx_pid} `killproc $nginxd-hup retval=$? Echo} # see how we were called.case "$1" instart) start;; stop) stop;; reload) reload;; restart) stop start;; status) status $prog retval=$?;; *) echo $"usage: $prog {start | stop | restart | status | help}" exit 1esacexit $retval:wq save and exit

* modify some of the file paths in the shell script to the corresponding path of nginx on your host, for example, nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid is the corresponding path of the nginx of the test machine, and the default path of nginx's pid is in the logs/nginx.pid of the nginx installation directory.

Set access to files

[root@localhost] # chmod adepx / etc/init.d/nginx

(Abacx = = > all user can execute executable for all users)

This makes it easy to operate nginx on the console: check the current status of nginx, start nginx, stop nginx, restart nginx.

Usage: nginx {start | stop | restart | reload | status | help}

If you modify the nginx configuration file nginx.conf, you can also use the above command to reload the new configuration file and run it. You can add this command to the rc.local file so that nginx starts by default when you boot.

Add to the rc.local file

[root@localhost] # vi / etc/rc.local

Add a line / etc/init.d/nginx start to save and exit, and the next restart will take effect.

Be careful

If you find that the startup script is not executed after booting, you need to make sure that the access to the rc.local file is executable, because rc.local is unexecutable by default.

Modify rc.local access rights to increase executable permissions

[root@localhost] # chmod + x / etc/rc.d/rc.local

Now, after the restart, the self-startup script can be executed normally.

You can view the operation of nginx with the following command

[root@localhost] # ps aux | grep nginx "how to solve the problem of Nginx boot self-startup in Centos7" is introduced here, thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Internet Technology

Wechat

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

12
Report