无法让虚拟主机与端口在 Apache 上运行

无法让虚拟主机与端口在 Apache 上运行

我正在尝试在本地主机上设置测试和实时站点。我已设置以下目录:/var/www/html/test/ /var/www/html/live/

因此,通过https://192.168.10.2,我希望它引用 /var/www/html/live/。(注意,我还没有尝试设置它)

通过前往http://192.168.10.2:1881,我希望它引用 /var/www/html/test/

这是我所拥有的:在 /etc/httpd/conf.d 中,我有一个名为 test.conf 的文件

NameVirtualHost *:1881

<VirtualHost *:1881>
ServerName 192.168.10.2
DocumentRoot /var/www/html/test

    <Directory "/var/www/html/test">
        Options MultiViews Indexes Includes FollowSymLinks ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

在 httpd.conf 中,我添加了该行(直接在 Listen 80 下):

Listen 1881

如果我去https://192.168.10.2/,我得到了我设置的测试页面。如果我去http://192.168.10.2:1881/,我收到“无法访问此站点 - ERR_CONNECTION_TIMED_OUT”

如果您需要更多配置文件,请告诉我。

编辑:我按照@DanGahan 的建议运行了命令

# netstat -anp | grep 1881
tcp6       0      0 :::1881                 :::*                    LISTEN      37931/httpd
# telnet 192.168.10.2:1881
telnet: 192.168.10.2:1881: Name or service not known
192.168.10.2:1881: Host name lookup failure

编辑2

# telnet 192.168.10.2 1881
Trying 192.168.10.2...
Connected to 192.168.10.2.
Escape character is '^]'.
Connection closed by foreign host.
#

编辑 3-IP 表

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     udp  --  anywhere             anywhere             udp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:domain
ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootps
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:bootps
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere
INPUT_direct  all  --  anywhere             anywhere
INPUT_ZONES_SOURCE  all  --  anywhere             anywhere
INPUT_ZONES  all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere             ctstate INVALID
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             192.168.122.0/24     ctstate RELATED,ESTABLISHED
ACCEPT     all  --  192.168.122.0/24     anywhere
ACCEPT     all  --  anywhere             anywhere
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere
FORWARD_direct  all  --  anywhere             anywhere
FORWARD_IN_ZONES_SOURCE  all  --  anywhere             anywhere
FORWARD_IN_ZONES  all  --  anywhere             anywhere
FORWARD_OUT_ZONES_SOURCE  all  --  anywhere             anywhere
FORWARD_OUT_ZONES  all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere             ctstate INVALID
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootpc
OUTPUT_direct  all  --  anywhere             anywhere

Chain FORWARD_IN_ZONES (1 references)
target     prot opt source               destination
FWDI_public  all  --  anywhere             anywhere            [goto]
FWDI_public  all  --  anywhere             anywhere            [goto]

Chain FORWARD_IN_ZONES_SOURCE (1 references)
target     prot opt source               destination

Chain FORWARD_OUT_ZONES (1 references)
target     prot opt source               destination
FWDO_public  all  --  anywhere             anywhere            [goto]
FWDO_public  all  --  anywhere             anywhere            [goto]

Chain FORWARD_OUT_ZONES_SOURCE (1 references)
target     prot opt source               destination

Chain FORWARD_direct (1 references)
target     prot opt source               destination

Chain FWDI_public (2 references)
target     prot opt source               destination
FWDI_public_log  all  --  anywhere             anywhere
FWDI_public_deny  all  --  anywhere             anywhere
FWDI_public_allow  all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere

Chain FWDI_public_allow (1 references)
target     prot opt source               destination

Chain FWDI_public_deny (1 references)
target     prot opt source               destination

Chain FWDI_public_log (1 references)
target     prot opt source               destination

Chain FWDO_public (2 references)
target     prot opt source               destination
FWDO_public_log  all  --  anywhere             anywhere
FWDO_public_deny  all  --  anywhere             anywhere
FWDO_public_allow  all  --  anywhere             anywhere

Chain FWDO_public_allow (1 references)
target     prot opt source               destination

Chain FWDO_public_deny (1 references)
target     prot opt source               destination

Chain FWDO_public_log (1 references)
target     prot opt source               destination

Chain INPUT_ZONES (1 references)
target     prot opt source               destination
IN_public  all  --  anywhere             anywhere            [goto]
IN_public  all  --  anywhere             anywhere            [goto]

Chain INPUT_ZONES_SOURCE (1 references)
target     prot opt source               destination

Chain INPUT_direct (1 references)
target     prot opt source               destination

Chain IN_public (2 references)
target     prot opt source               destination
IN_public_log  all  --  anywhere             anywhere
IN_public_deny  all  --  anywhere             anywhere
IN_public_allow  all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere

Chain IN_public_allow (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh ctstate NEW
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https ctstate NEW
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:memcache ctstate NEW

Chain IN_public_deny (1 references)
target     prot opt source               destination

Chain IN_public_log (1 references)
target     prot opt source               destination

Chain OUTPUT_direct (1 references)
target     prot opt source               destination
#

答案1

httpd.conf 配置非常简单

Listen 80
Listen 1881

NameVirtualHost *:80
<VirtualHost *:80>
ServerName 192.168.10.2
DocumentRoot /var/www/html/live
</VirtualHost>

NameVirtualHost *:1881
<VirtualHost *:1881>
ServerName 192.168.10.2
DocumentRoot /var/www/html/test
</VirtualHost>

应该可以解决问题。运行“netstat -anp | grep 1881”以确认您在监听新端口,如果看起来不错,请尝试与其建立 tcp 连接以确认连通性“telnet 192.168.10.2 1881”- 如果失败,请检查 iptables

相关内容