2023年11月27日发(作者:)

正文

Nginx编译安装时常见错误分析

TypeCodes 06-22 17:02



这篇文章主要是关于Nginx在编译安装时,可能出现的错误的解决方法。Nginx正确的编译安装操作见前文 《2015博客升级记(三):CentOS 7.1编译安装Nginx1.9.0》 。



1 Nginx启动脚本错误:env: /etc/init.d/nginx: No such file or directory



明明上传了Nginx服务控制脚本 nginx ,但是在执行 service nginx start 命令时,却会报上面的错误。



解决方法:启动脚本的格式有问题,例如该脚本是dos格式,在Linux系统是中无法识别的。可以通过vim打开该文件,如果可以看到出现 ^M 的字符,就可以确定是DOS格式的了。那么可以在vim中执行命令 :%s/
+$//e ,将其转换成Unix格式即可。



2 启动Nginx服务失败



安装完Nginx后,执行命令 service nginx start 失败,即无法正常启动Nginx服务。



[root@typecodes init.d]# service nginx start

Starting nginx (via systemctl): Warning: Unit file of e changed on disk, 'systemctl daemon-reload' recommended.

Job for e failed. See 'systemctl status e' and 'journalctl -xn' for details.

[FAILED]



解决方法:主要通过命令 systemctl status e 来分析,如下图所示。



[编译MySQL5.7.7rc的make命令执行结果]



很明显是由于下面这个错误,导致Nginx服务启动失败。



Apr 11 21:43:07 typecodes nginx[4026]: Starting nginx: nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)



这种错误一般都是目录不存在或者权限不足,所以直接执行下面两条命令即可。



[root@typecodes ~]# cd /var/tmp/

[root@typecodes ~]# mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}



3 启动Nginx服务时,界面卡住



在敲入命令 service nginx restart 后,终端界面能卡住,也就是Nginx服务控制脚本 nginx 没有正常执行完毕。在停止Nginx服务后,发现Nginx进程还存在。



#######启动Nginx服务出现警告

[root@typecodes init.d]# service nginx restart

Restarting nginx (via systemctl): Warning: Unit file of e changed on disk, 'systemctl daemon-reload' recommended.

Restarting nginx (via systemctl): Warning: Unit file of e changed on disk, 'systemctl daemon-reload' recommended.

^C ######终端界面卡住,使用ctrl+c命令强制结束



#######停掉Nginx服务

[root@typecodes init.d]# service nginx stop

Stopping nginx (via systemctl): [ OK ]



#######查看Nginx进程是否已被停止(可以看到未停止)

[root@typecodes init.d]# ps -aux|grep nginx

root 7796 0.0 0.2 84184 2044 ? Ss 21:14 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/

nginx 7798 0.0 0.3 86656 3380 ? S 21:14 0:00 nginx: worker process

root 7981 0.0 0.0 112644 964 pts/0 S+ 21:19 0:00 grep --color=auto nginx