在安装完Nginx后服务启动失败的解决办法

问题:

在我安装完Nginx后,想要启动服务,但是启动失败,并报出如下提示:

systemctl start nginx  //启动服务
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.     //提示信息

问题分析

然后我就按照问题提示的命令查看了一下,然后就输出如下内容:

journalctl -xe
1月 01 20:14:07 localhost.localdomain nginx[7788]: nginx: configuration file /etc/nginx/nginx.conf test is successf
1月 01 20:14:07 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already 
1月 01 20:14:07 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in 
1月 01 20:14:08 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already 
1月 01 20:14:08 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in 
1月 01 20:14:08 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already 
1月 01 20:14:08 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in 
1月 01 20:14:09 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already 
1月 01 20:14:09 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in 
1月 01 20:14:09 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already 
1月 01 20:14:09 localhost.localdomain nginx[7791]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in 
1月 01 20:14:10 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
1月 01 20:14:10 localhost.localdomain nginx[7791]: nginx: [emerg] still could not bind()
1月 01 20:14:10 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has failed.
-- 
-- The result is failed.
1月 01 20:14:10 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
1月 01 20:14:10 localhost.localdomain systemd[1]: nginx.service failed.
1月 01 20:14:10 localhost.localdomain polkitd[6139]: Unregistered Authentication Agent for unix-process:7781:265264

从输出的提示信息上可以看到”0.0.0.0:80 failed”字样,大概可能跟端口有关,然后再使用如下命令查看一下端口进程:
在这里插入图片描述
通过监听端口,发现80端口已经被占用了,怪不得Nginx服务起不来,因为httpd和Nginx默认的监听端口一样。

解决办法

想要让Nginx服务启动起来有两种方法:
方法1: 停止之前的httpd服务

systemctl stop httpd

方法2: 修改Nginx服务的默认监听端口

vim /etc/nginx/nginx.conf
server {
        listen       8080 default_server;
        listen       [::]:8080 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

然后再次启动Nginx服务就没有问题了

systemctl start nginx
systemctl enable nginx

已经监听nginx
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值