I CAN'T GIVE YOU THE WORLD, BUT I CAN GIVE YOU MY WORLD.

Nginx启动失败,80端口被Apache占用

如何解决Apache占用端口问题

刚刚查看了一下下载的站点,发现显示是Apache的默认展示首页。我以为服务器挂了,被服务商重新安装了系统导致下载站点就挂了。吓的心拔凉拔凉的。

Baerk尝试登录宝塔的面板,还好,能登录上去。在首页就看到Nginx已经处于停止运行状态,如何Baerk尝试了重启Nginx,发现根本启动不了。到官方论坛尝试搜索解决方案,建议连接SSH启动Nginx服务:

[root@restorevps ~]# service nginx start

Starting nginx… nginx: [warn] only the last index in “index” directive should be absolute in /www/server/panel/vhost/nginx/www.src.zt.tn.conf:5

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

failed

同样启动失败,可以发现是80端口被占用。使用命令

lsof -i :80

查看端口被哪个服务占用

[root@restorevps ~]# lsof -i :80

COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

httpd    108   root    4u  IPv6 300575      0t0  TCP *:http (LISTEN)

httpd   1129 apache    4u  IPv6 300575      0t0  TCP *:http (LISTEN)

httpd   1131 apache    4u  IPv6 300575      0t0  TCP *:http (LISTEN)

httpd   1954 apache    4u  IPv6 300575      0t0  TCP *:http (LISTEN)

httpd   2598 apache    4u  IPv6 300575      0t0  TCP *:http (LISTEN)

httpd   2599 apache    4u  IPv6 300575      0t0  TCP *:http (LISTEN)

感觉到很奇怪,什么时候安装了的Apache?确认下是否有安装过,或者是系统自带了httpd服务,通过以下命令

[root@restorevps ~]# rpm -qa|grep httpd

httpd-2.4.6-45.el7.centos.4.x86_64

httpd-tools-2.4.6-45.el7.centos.4.x86_64

[root@restorevps ~]# rpm -e httpd-2.4.6-45.el7.centos.4.x86_64

error: Failed dependencies:

httpd-mmn = 20120211×8664 is needed by (installed) mod_ssl-1:2.4.6-45.el7.centos.4.x86_64

httpd = 0:2.4.6-45.el7.centos.4 is needed by (installed) mod_ssl-1:2.4.6-45.el7.centos.4.x86_64

或者尝试另一个方法

[root@restorevps ~]# yum list|grep httpd

httpd.x86_64                             2.4.6-45.el7.centos.4          @updates

httpd-tools.x86_64                       2.4.6-45.el7.centos.4          @updates

darkhttpd.x86_64                         1.11-1.el7                     epel

httpd-devel.x86_64                       2.4.6-45.el7.centos.4          updates

httpd-itk.x86_64                         2.4.7.04-2.el7                 epel

httpd-manual.noarch                      2.4.6-45.el7.centos.4          updates

iipsrv-httpd-fcgi.noarch                 1.0.0-6.0.el7                  epel

libmicrohttpd.i686                       0.9.33-2.el7                   base

libmicrohttpd.x86_64                     0.9.33-2.el7                   base

libmicrohttpd-devel.i686                 0.9.33-2.el7                   base

libmicrohttpd-devel.x86_64               0.9.33-2.el7                   base

libmicrohttpd-doc.noarch                 0.9.33-2.el7                   base

lighttpd.x86_64                          1.4.45-1.el7                   epel

lighttpd-fastcgi.x86_64                  1.4.45-1.el7                   epel

lighttpd-mod_authn_gssapi.x86_64         1.4.45-1.el7                   epel

lighttpd-mod_authn_mysql.x86_64          1.4.45-1.el7                   epel

lighttpd-mod_geoip.x86_64                1.4.45-1.el7                   epel

lighttpd-mod_mysql_vhost.x86_64          1.4.45-1.el7                   epel

mirmon-httpd.noarch                      2.11-1.el7                     epel

nextcloud-httpd.noarch                   10.0.4-2.el7                   epel

opensips-httpd.x86_64                    1.10.5-3.el7                   epel

owncloud-httpd.noarch                    9.1.5-1.el7                    epel

python2-sphinxcontrib-httpdomain.noarch  1.5.0-3.el7                    epel

radicale-httpd.noarch                    1.1.2-1.el7                    epel

sysusage-httpd.noarch                    5.5-3.el7                      epel

viewvc-httpd-fcgi.noarch                 1.1.26-1.el7                   epel

viewvc-httpd-wsgi.noarch                 1.1.26-1.el7                   epel

web-assets-httpd.noarch                  5-1.el7                        epel

[root@restorevps ~]# yum erase httpd.x86_64

Loaded plugins: fastestmirror

Resolving Dependencies

–> Running transaction check

—> Package httpd.x86_64 0:2.4.6-45.el7.centos.4 will be erased

–> Processing Dependency: httpd-mmn = 20120211×8664 for package: 1:mod_ssl-2.4.6-45.el7.centos.4.x86_64

–> Processing Dependency: httpd for package: 1:mod_ssl-2.4.6-45.el7.centos.4.x86_64

–> Processing Dependency: httpd = 2.4.6-45.el7.centos.4 for package: 1:mod_ssl-2.4.6-45.el7.centos.4.x86_64

–> Running transaction check

—> Package mod_ssl.x86_64 1:2.4.6-45.el7.centos.4 will be erased

–> Finished Dependency Resolution

 

Dependencies Resolved

 

========================================================================================

Package         Arch           Version                          Repository        Size

========================================================================================

Removing:

httpd           x86_64         2.4.6-45.el7.centos.4            @updates         9.4 M

Removing for dependencies:

mod_ssl         x86_64         1:2.4.6-45.el7.centos.4          @updates         224 k

 

Transaction Summary

========================================================================================

Remove  1 Package (+1 Dependent package)

 

Installed size: 9.6 M

Is this ok [y/N]: y

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Erasing    : 1:mod_ssl-2.4.6-45.el7.centos.4.x86_64                               1/2

Erasing    : httpd-2.4.6-45.el7.centos.4.x86_64                                   2/2

Verifying  : httpd-2.4.6-45.el7.centos.4.x86_64                                   1/2

Verifying  : 1:mod_ssl-2.4.6-45.el7.centos.4.x86_64                               2/2

 

Removed:

httpd.x86_64 0:2.4.6-45.el7.centos.4

 

Dependency Removed:

mod_ssl.x86_64 1:2.4.6-45.el7.centos.4

 

Complete!

我先来卸载我的httpd,首先要停止httpd服务,命令如下:
systemctl stop httpd.service
然后通过 rpm -e 或者yum -erase 命令都可以,不过rpm -e命名必须要自己先卸载依赖包,所以我用yum -erase命令卸载,命令如下:
yum erase httpd.x86_64
中间会问一下是否确认,y就可以了,直到出现Complete! 代表卸载完成了。

点赞