使用 https 通过多个虚拟主机访问网站

使用 https 通过多个虚拟主机访问网站

我有一台 apache 服务器,位于运行于 Windows Server 2012 上的 JIRA Service Desk 实例前面。

JIRA 中有 2 个客户门户,我需要设置 Apache,以便每个客户门户都可以通过不同的虚拟主机访问。

像这样:

这是我目前所拥有的:

<VirtualHost *:80>
RewriteEngine on
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
RewriteRule ^/$ /servicedesk/customer/portal/1/ [R=301]
DocumentRoot "c:/Apache24/htdocs"
#Redirect permanent / https://www.it.mysite.com/  # tried this, it seemed to be ignored
ServerName www.it.mysite.com
ServerAlias it.mysite.com
....
</VirtualHost>


<VirtualHost *:80>
RewriteEngine on
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
RewriteRule ^/$ /servicedesk/customer/portal/2/ [R=301]
DocumentRoot "c:/Apache24/htdocs"
#Redirect permanent / https://www.as.mysite.com/  # tried this, it seemed to be ignored
ServerName www.as.mysite.com
ServerAlias as.mysite.com
....
</VirtualHost>



<VirtualHost *:443>
RewriteEngine on
RewriteRule ^/$ /servicedesk/customer/portal/1 [R=301] 
RewriteRule ^/servicedesk/customer/portals$ https://it.mysite.com/servicedesk/customer/portal/1 [R=301] 
DocumentRoot "c:/Apache24/htdocs"
ServerName www.it.mysite.com
ServerAlias it.mysite.com
...
</VirtualHost>



<VirtualHost *:443>
RewriteEngine on
RewriteRule ^/$ /servicedesk/customer/portal/2 [R=301] 
RewriteRule ^/servicedesk/customer/portals$ https://as.mysite.com/servicedesk/customer/portal/2 [R=301] 
DocumentRoot "c:/Apache24/htdocs"
ServerName www.as.mysite.com
ServerAlias as.mysite.com
...
</VirtualHost>

一切似乎都按预期进行。mysite.com

但是,如果我访问 as.mysite.com,我会得到: https://it.mysite.com/servicedesk/customer/portal/2

Https 重定向有效,显示了正确的门户 (2),但是域名恢复为it.mysite.com

我访问的任何页面都会发生同样的情况。例如:-as.mysite.com/somepage.html让我https://as.mysite.com/somepage.html

的输出为C:\apache24\bin\httpd -S

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server www.it.mysite.com (C:/Apache24/conf/httpd.conf:541)
         port 80 namevhost www.it.mysite.com (C:/Apache24/conf/httpd.conf:541)
                 alias it.mysite.com
         port 80 namevhost www.as.mysite.com (C:/Apache24/conf/httpd.conf:562)
                 alias as.mysite.com
*:443                  is a NameVirtualHost
         default server www.it.mysite.com (C:/Apache24/conf/httpd.conf:596)
         port 443 namevhost www.it.mysite.com (C:/Apache24/conf/httpd.conf:596)
                 alias it.mysite.com
         port 443 namevhost www.as.mysite.com (C:/Apache24/conf/httpd.conf:636)
                 alias as.mysite.com
ServerRoot: "C:/Apache24"
Main DocumentRoot: "C:/Apache24/htdocs"
Main ErrorLog: "C:/Apache24/logs/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="C:/Apache24/logs/" mechanism=default
PidFile: "C:/Apache24/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG

C:\Windows\system32>

我怎样才能让它保留as子域名?

答案1

您的虚拟主机看起来不错。我将执行以下操作来排除故障

1)每次测试前,明确清除浏览器缓存,或者使用 curl 等命令行工具测试请求

2)向每个虚拟主机添加特定于虚拟主机的访问/错误日志,以确保您发出的请求到达正确的虚拟主机

3) 启用 mod_rewrite 日志记录来调试重写。详细信息请参见此处:http://wiki.apache.org/httpd/RewriteLog

相关内容