linux编译安装nginx失败怎么办?排错思路及方法

1.分析:
nginx编译安装失败一般会出现在三个方面

  • 编译环境安装不全
  • 安装的时候参数出错
  • 配置文件修改出错

2.编译环境安装不全
如果你的编译环境安装的不全,在你编译安装的时候可能会报错

[root@localhost nginx-1.16.1]# make && make install   
[root@localhost nginx-1.16.1]# echo $?    
#当你执行完make install命令之后,执行echo $?这个命令,如果你发现结果不是0,说明你的环境有问题,你需要重新安装一下自己的环境

3.安装的时候参数出错

[root@localhost nginx-1.16.1]# /usr/local/nginx/sbin/nginx
nginx: [emerg] getpwnam("nginx") failed
#当你安装成功的时候用绝对路径发现服务起不来,而且也不是环境的问题,那么很有可能是你的参数以及依赖包出错了

此时用下面的命令看一下

[root@localhost nginx-1.16.1]# /usr/local/nginx/sbin/nginx -t #查看配置文件是否出错
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
nginx: [emerg] getpwnam("nginx") failed
nginx: configuration file /etc/nginx/nginx.conf test failed

发现我们指定的配置文件路径测试失败,那我们再安装一下路径

[root@localhost nginx-1.16.1]# ./configure --sbin-path=/usr/local/nginx/sbin/nginx
[root@localhost nginx-1.16.1]# /usr/local/nginx/sbin/nginx  
[root@localhost ~]# ps -ef |grep nginx
root      35936      1  0 04:00 ?        00:00:00 nginx: master process nginx
nobody    35937  35936  0 04:00 ?        00:00:00 nginx: worker process
root      41608   1140  0 04:05 pts/0    00:00:00 grep --color=auto nginx

此时你发现成功了。
4.配置文件修改出错

输入下面的命令,如果你的配置文件出错了,就会显示你大致在哪行出错了
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t

5.如果你的服务起来了但是访问不到网页,你肯定是防火墙跟selinux没关

[root@localhost ~]# systemctl stop firewalld && setenforce 0

6.如果做了以上步骤启动nginx还是失败,那你就要好好检查检查你的环境了,或者重新做。我这里有详细的安装步骤,每一步是干什么的都有清楚的解释,连接如下:
linux编译安装详解

发布了10 篇原创文章 · 获赞 18 · 访问量 1598

猜你喜欢

转载自blog.csdn.net/baidu_38803985/article/details/104755768