1 测试环境nginx服务起不来,提示 Failed to start nginx.service: Unit not found.
原因是: /etc/init.d/目录下面缺少nginx启动文件造成的。
在/etc/init.d/目录下新建nginx文件并写以下代码:
#!/bin/bash # # chkconfig: - 85 15 # description: nginx is a World Wide Web server. It is used to serve # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/export/servers/nginx/sbin/nginx" NGINX_CONF="/export/servers/nginx/conf/nginx.conf" NGINX_PID="/export/servers/nginx/logs/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart(){ stop start } configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL
更改文件权限 sudo chmod 755 nginx