我真的不知道如何解决这个问题。我需要在地址http://domain.com:12345/上加载页面http://sub.domain.com/。
当我只有一个IP地址时,如何在Apache上设置VirtualHost或Alias?
非常感谢。
现在我有这个:
ports.conf:
NameVirtualHost domain.com:80
NameVirtualHost sub.domain.com:80
Listen *:80
<IfModule mod_ssl.c>
Listen *:443
</IfModule>
<IfModule mod_gnutls.c>
Listen *:443
</IfModule>
... /站点可用/默认:
<VirtualHost domain.com:80>
ServerAdmin admin@domain.com
ServerName domain.com
DocumentRoot /var/www
...
</VirtualHost>
<VirtualHost sub.domain.com:80>
ServerAdmin admin@domain.com
ServerName sub.domain.com
ProxyPass / http://www.domain.com:12345/
ProxyPassReverse / http://www.domain.com:12345/
</VirtualHost>
但这不起作用。 sub.domain.com返回500内部服务器错误。
答案 0 :(得分:0)
解决方案是虚拟主机:
如果您想在您的网站上维护多个域/主机名 您可以为他们设置VirtualHost容器。大多数配置 仅使用基于名称的虚拟主机,因此服务器无需担心 IP地址。这由以下指令中的星号表示。
请参阅文档 http://httpd.apache.org/docs/2.2/vhosts/ 有关进一步的详细信息,请在尝试设置虚拟主机之前。
您可以使用命令行选项'-S'来验证您的虚拟主机 配置。
这是一个配置示例:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin postmaster@dummy-host.localhost
DocumentRoot "C:/Program Files (x86)/www/htdocs/dummy-host.localhost"
ServerName dummy-host.localhost
ServerAlias www.dummy-host.localhost
ErrorLog "logs/dummy-host.localhost-error.log"
CustomLog "logs/dummy-host.localhost-access.log" combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot "C:/Program Files (x86)/www/htdocs/dummy-host2.localhost"
ServerName dummy-host2.localhost
ServerAlias www.dummy-host2.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>