RockyLinux 9. 重启时 Apache 无法启动,并显示以下消息
Jul 21 10:53:13 cl httpd[877]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address 1.2.3.4:80
Jul 21 10:53:13 cl httpd[877]: no listening sockets available, shutting down
Jul 21 10:53:13 cl httpd[877]: AH00015: Unable to open logs
Jul 21 10:53:13 cl systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE
Jul 21 10:53:13 cl systemd[1]: httpd.service: Failed with result 'exit-code'.
Jul 21 10:53:13 cl systemd[1]: Failed to start The Apache HTTP Server.
主配置文件将其设置为监听该地址和 80 端口。但该地址的 80 和 443 端口上都有虚拟主机
如果我手动启动它,它会开始使用该地址,但 443 端口
# systemctl start httpd
Jul 21 10:55:44 cl systemd[1]: Starting The Apache HTTP Server...
Jul 21 10:55:44 cl httpd[2135]: [Fri Jul 21 10:55:44.803045 2023] [so:warn] [pid 2135:tid 2135] AH01574: module wsgi_module is already loaded, skipping
Jul 21 10:55:44 cl httpd[2135]: Server configured, listening on: 1.2.3.4 port 443, ...
Jul 21 10:55:44 cl systemd[1]: Started The Apache HTTP Server.
有任何想法吗?
# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 879/sshd: /usr/sbin
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1551/postmaster
tcp 0 0 1.2.3.4:80 0.0.0.0:* LISTEN 2574/httpd
tcp 0 0 1.2.3.4:443 0.0.0.0:* LISTEN 2574/httpd
tcp6 0 0 :::22 :::* LISTEN 879/sshd: /usr/sbin
udp 0 0 127.0.0.1:323 0.0.0.0:* 810/chronyd
udp6 0 0 ::1:323 :::* 810/chronyd
# cat /etc/NetworkManager/system-connections/System\ enp0s71fa.nmconnection
[connection]
id=System enp0s71fa
uuid=b5f5eeee-5bd2-c5a6-acb6-f03d5581aca5
type=ethernet
interface-name=enp0s71fa
timestamp=1689890116
[ethernet]
[ipv4]
address1=1.2.3.4/32,1.2.3.6
address2=1.2.3.5/27
dns=5.6.7.1;
method=manual
[ipv6]
address1=2a01:4f8:bbb:aaaa::2/64,fe80::1
dns=2a01:ccc:dddd::add:2;
method=manual
答案1
我的解决方案是覆盖/usr/lib/systemd/system/httpd.service
:
# systemctl edit httpd
添加network-online.target
到After
:
### Editing /etc/systemd/system/httpd.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file
[Unit]
After=network.target network-online.target remote-fs.target nss-lookup.target httpd-init.service
### Lines below this comment will be discarded