🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## Nginx安装,设置成系统服务 >[success] nginx默认是不支持系统服务的,如果要想添加成系统服务,需要编一如下脚本:vi /etc/init.d/nginx 里面的部分内容,要根据实际的安装路径进行修改 ~~~ #! /bin/sh # chkconfig: - 85 15 PATH=/usr/local/nginx/sbin/ DESC="nginx daemon" NAME=nginx DAEMON=/usr/local/nginx/sbin/$NAME CONFIGFILE=/usr/local/nginx/conf/$NAME.conf PIDFILE=/usr/local/nginx/logs/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set -e [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running" } do_stop() { $DAEMON -s stop || echo -n "nginx not running" } do_reload() { $DAEMON -s reload || echo -n "nginx can't reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;; esac exit 0 ~~~ ### nginx脚本创建好后 #### 1、添加执行权限 ~~~ chmod 755 /etc/rc.d/init.d/nginx ~~~ #### 2、添加服务 ~~~ chkconfig --add nginx ~~~ #### 3、测试 ~~~ service nginx start service nginx stop service nginx restart service nginx reload ~~~