为什么我在启动Apache2时收到“权限被拒绝:make_sock:无法绑定到地址”?
我可以阻止它使用
/etc/init.d/apache2 stop
但是当我想再次使用时启动它:
/etc/init.d/apache2 start
我收到此错误:
Starting web server apache2 /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted) apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName (13)Permission denied: make_sock: could not bind to address [::]:80 (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs Action 'start' failed. The Apache error log may have more information. [fail]
关于你得到的错误的一些话,希望将来可以避免类似的情况。
在Linux中,0到1024的端口保留供系统使用。 这意味着,要使用一个,您必须有权更改 – 访问基本系统设置。 root用户具有此类权限,实际上可以使用0到1024范围内的端口。
在您的问题中,您可以看到,系统通过Apache2响应指示问题的根源([…]无法绑定到地址等等等等):
(13)Permission denied: make_sock: could not bind to address [::]:80 (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
当Apache2 http守护程序启动时,它会尝试绑定80端口,因为它是在HTTP中使用的默认端口,这是系统分配端口中的端口,因此只能由root访问。
您以没有root权限的典型用户身份执行了start命令,导致无法执行此操作。
简单来说:
您:
嗨Apache2我是Kongthap,我告诉你开始(
/etc/init.d/apache2 start
)
Apache2的:
好的我开始了(启动web服务器apache2)
系统请给我端口80使用和听取连接
系统:
好的一刻检查
啊对不起Apache2但是我不能让你在80端口运行,它是供个人使用的
并且您没有正确的绑定权限。(
Operation not permitted
)
Apache2的:
哦,Kongthap我没能开始,系统没让我这么做((13)许可被拒绝:[…])
结论
这个问题主要有两个解决方案:
-
使用sudo以root权限运行Apache2 http守护程序:
sudo service apache2 start
要么:
sudo /etc/init.d/apache2 start
-
将默认端口从
80
更改为大于1024
,例如9000
等。在这种情况下运行的典型端口是8080
sudo vi /etc/apache2/ports.conf
寻找或如果没有添加:
Listen 8080
或您选择的任何其他端口,例如端口
> 1024
并且其他进程不使用所选端口。
以下是启动/停止/重启apache服务器的命令:
-
开始:
sudo /etc/init.d/apache2 start
-
停止:
sudo /etc/init.d/apache2 stop
-
重启:
sudo /etc/init.d/apache2 restart
通过发出命令检查selinux端口上下文
semanage port -l | grep http
如果它出现在http_port_t列表中,则表示没问题,否则请添加您的端口
semanage port -a -t http_port_t -p tcp 80
或者你想要分配的东西。
这是一个selinux错误,或者至少在我的情况下。 更改布尔值,禁用selinux,或使用setenforce 0
将其设置为允许。
布尔值的改变需要你运行getenforce -a | grep http
getenforce -a | grep http
,并寻找“允许http连接网络”。 复制它并替换“on”,其中列表显示“ – off”