在 Apache 2.2.22 中,我尝试运行两个虚拟主机,它们具有两个 IP 地址和两个 SSL 证书。除了配置虚拟主机的文件之外,我没有在任何其他配置文件中监听端口或 NameVirtualHost。在实现此功能的过程中,我希望使用最少的代码。
在 sites-available 目录中我有 site1.com 配置文件:
NameVirtualHost 1.1.1.1:80
Listen 1.1.1.1:80
Listen 1.1.1.1:443
<VirtualHost 1.1.1.1:80>
ServerAdmin [email protected]
ServerName site1.com
ServerAlias www.site1.com
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule (.*) https://www.site1.com/ [R]
</VirtualHost>
<VirtualHost 1.1.1.1:443>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /home/j/site1/public
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/site1.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/site1.com.key
SSLCertificateChainFile /etc/apache2/ssl/gd_bundle_site1.crt
LogLevel warn
ErrorLog /home/j/site1/log/error.log
CustomLog /home/j/site1/log/access.log combined
</VirtualHost>
如果 site1.com 是唯一启用的站点,则服务器可以正常启动。当我启用 site2.com 时,我遇到了麻烦。Sudo apachectl configtest
结果为,Syntax OK
但重新启动 apache 会导致(99)Cannot assign requested address: make_sock: could not bind to address 2.2.2.2:8080 no listening sockets available, shutting down Unable to open logs Action 'start' failed.
以下是 site2.com 的内容:
NameVirtualHost 2.2.2.2:8080
Listen 2.2.2.2:8080
Listen 2.2.2.2:4430
<VirtualHost 2.2.2.2:8080>
ServerAdmin [email protected]
ServerName site2.com
ServerAlias www.site2.com
RewriteEngine On
RewriteCond %{SERVER_PORT} !4430
RewriteRule (.*) https://www.site2.com/ [R]
</VirtualHost>
<VirtualHost 2.2.2.2:4430>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot /home/j/site2/public
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/site2.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/site2.key
SSLCertificateChainFile /etc/apache2/ssl/gd_bundle_site2.crt
LogLevel warn
ErrorLog /home/j/site2/log/error.log
CustomLog /home/j/site2/log/access.log combined
</VirtualHost>
感谢您的帮助。
更新:
netstat -lpn less udp6 的结果:
(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 1.1.1.1:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:7187 0.0.0.0:* LISTEN -
tcp 0 0 1.1.1.1:443 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:55363 0.0.0.0:* LISTEN -
tcp6 0 0 :::7187 :::* LISTEN -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
udp 0 0 1.1.1.1:123 0.0.0.0:* -
udp 0 0 127.0.0.1:123 0.0.0.0:* -
udp 0 0 0.0.0.0:123 0.0.0.0:* -
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 169974 - /tmp/passenger.1.0.32045/generation-0/spawn-server/socket.32055.19978820
unix 2 [ ACC ] STREAM LISTENING 2823 - @/tmp/fam-root-
unix 2 [ ACC ] STREAM LISTENING 180580 - /tmp/passenger.1.0.32045/generation-0/backends/ruby.ui0IFvdXouP5Ukb3zZo2fiLBEJOgc5835cbcGK93fhrs5ogoitaPfi1
unix 2 [ ACC ] STREAM LISTENING 10547 - /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 106 - @/com/ubuntu/upstart
unix 2 [ ACC ] STREAM LISTENING 182366 - /var/run/apache2/cgisock.32045
unix 2 [ ACC ] STREAM LISTENING 395 - /var/run/dbus/system_bus_socket
unix 2 [ ACC ] SEQPACKET LISTENING 168 - /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 12724 - /var/run/fail2ban/fail2ban.sock
unix 2 [ ACC ] STREAM LISTENING 181619 - /tmp/passenger.1.0.32045/generation-0/socket
unix 2 [ ACC ] STREAM LISTENING 181621 - /tmp/passenger.1.0.32045/generation-0/spawn-server/socket.32053.32793072
unix 2 [ ACC ] STREAM LISTENING 181640 - /tmp/passenger.1.0.32045/generation-0/logging.socket
更新:
grep -r Listen /etc/apache2 除了上面提到的之外,没有对端口 8080 上的 Listen 进行任何引用。
更新:
根据下面 Jenny D 的建议,ifconfig -a 产生以下内容:
dummy0 Link encap:Ethernet HWaddr be:fc:55:b0:9e:80
BROADCAST NOARP MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth0 Link encap:Ethernet HWaddr f2:3c:91:70:34:84
inet addr:50.116.59.14 Bcast:50.116.59.255 Mask:255.255.255.0
inet6 addr: 2600:3c03::f03c:91ff:fe70:3484/64 Scope:Global
inet6 addr: fe80::f03c:91ff:fe70:3484/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:69078 errors:0 dropped:0 overruns:0 frame:0
TX packets:41852 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16773617 (16.7 MB) TX bytes:69148409 (69.1 MB)
Interrupt:76
gre0 Link encap:UNSPEC HWaddr 00-00-00-00-34-84-00-00-00-00-00-00-00-00-00-00
NOARP MTU:1476 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ip6gre0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
NOARP MTU:1448 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ip6tnl0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
NOARP MTU:1452 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ip_vti0 Link encap:IPIP Tunnel HWaddr
NOARP MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:3487 errors:0 dropped:0 overruns:0 frame:0
TX packets:3487 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:62766 (62.7 KB) TX bytes:62766 (62.7 KB)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
tunl0 Link encap:IPIP Tunnel HWaddr
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
答案1
此错误可能是由于Listen
针对同一 IP 地址/端口组合有两个指令而导致的。
由于您netstat
没有看到端口 8080 上有任何监听,我强烈怀疑这是您的问题。
尝试grep -r Listen /etc/apache2
找到它们。
答案2
难以置信。这是防火墙的问题。必须添加端口。