安装nginx后,使用命令service nginx start启动nginx服务是,无法启动,会报如下错误
这是因为服务器未设置nginx启动脚本,那么需要在/etc/init.d/目录下创建nginx的启动文件
方法:
执行 vi /etc/init.d/nginx
进入文件,将以下内容复制到nginx文件,并保存
1 #!/bin/bash 2 #Startup script for the nginx Web Server 3 #chkconfig: 2345 85 15 4 nginx=/usr/local/nginx/sbin/nginx 5 conf=/usr/local/nginx/conf/nginx.conf 6 case $1 in 7 start) 8 echo -n "Starting Nginx" 9 $nginx -c $conf 10 echo " done." 11 ;; 12 stop) 13 echo -n "Stopping Nginx" 14 killall -9 nginx 15 echo " done." 16 ;; 17 test) 18 $nginx -t -c $conf 19 echo "Success." 20 ;; 21 reload) 22 echo -n "Reloading Nginx" 23 ps auxww | grep nginx | grep master | awk ‘{print $2}‘ | xargs kill -HUP 24 echo " done." 25 ;; 26 restart) 27 $nginx -s reload 28 echo "reload done." 29 ;; 30 *) 31 echo "Usage: $0 {start|restart|reload|stop|test|show}" 32 ;; 33 esac
执行 service nginx start后报无权限错误,这时候需要处理文件权限
执行 chmod 755 nginx即可,
再次启动服务
命令扩展:
service nginx start 启动
service nginx stop 关闭
servcie nginx reload 重新加载
参考博客:https://www.cnblogs.com/lwhctv/p/9132857.html
原文:https://www.cnblogs.com/donglovebobo/p/14052728.html