在 apache 2.2.3 上设置通配符子域(使用反向代理)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1187289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting up Wildcard subdomain (with reverse proxy) on apache 2.2.3
提问by
What I am trying to achieve is the following: I want to have numerous subdomains such as abc.domain.comredirect to a url such as www.domain.com/something?subdomain=abc
我想要实现的目标如下:我希望将多个子域(例如abc.domain.com)重定向到一个 url,例如www.domain.com/something?subdomain=abc
Since I am redirecting to a fully qualified domain, I needed to use a reverse proxy to avoid the change of the URL in the browser. (using the [P] Flag and turning on the mod_proxy module and some other modules)
由于我要重定向到完全限定的域,因此我需要使用反向代理来避免浏览器中 URL 的更改。(使用 [P] 标志并打开 mod_proxy 模块和其他一些模块)
This is my DNS setup
这是我的 DNS 设置
*.domain.com. 14400 A 111.111.11.1
This is my virtual host configuration for apache
这是我的 apache 虚拟主机配置
<VirtualHost 111.111.11.1:80>
ServerName www.domain.com
ServerAlias *.lionite.com
DocumentRoot /var/www/html
ErrorLog /var/www/logs
UseCanonicalName off
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule ^(.+) %{HTTP_HOST} [C]
RewriteRule ^([^.]+)\.domain\.com(.*) http://www.domain.com/something?subdomain= [P,L]
This setup is working fine (Let me know if you think you can improve it of course).
此设置运行良好(如果您认为您当然可以改进它,请告诉我)。
My main problem is when I am trying to setup https://
我的主要问题是当我尝试设置 https://
This is my virtual host configuration for apache
这是我的 apache 虚拟主机配置
<VirtualHost 111.111.11.1:443>
ServerName www.domain.com:443
ServerAlias *.domain.com
DocumentRoot /var/www/html
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/httpd/conf.d/cert/server.crt
SSLCertificateKeyFile /etc/httpd/conf.d/cert/server.key
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images
RewriteCond %{HTTPS_HOST} !^www\.domain\.com$
RewriteRule ^(.+) %{HTTPS_HOST} [C]
RewriteRule ^([^.]+)\.domain\.com(.*) https://www.domain.com/something?subdomain= [P,L]
</VirtualHost>
Whenever I call https://abc.domain.com- the response I am getting is the homepage but no matter what I am appending to the end of the subdomain, I will get the same response. It's like the rewrite isn't responding well.
每当我调用https://abc.domain.com- 我得到的响应是主页,但无论我在子域的末尾附加什么,我都会得到相同的响应。就像重写没有反应好。
Any help would be appreciated, or if you could share how you'd setup reverse proxy, rewrite, wildcard subdomain and SSL all together
任何帮助将不胜感激,或者如果您可以分享您如何一起设置反向代理、重写、通配符子域和 SSL
Thanks,
谢谢,
采纳答案by Mike
I have had this same problem as well. The only way I solved it was to put different domains that need secure connection on different Listen ports because I was limited with IP addresses.
我也有同样的问题。我解决它的唯一方法是将需要安全连接的不同域放在不同的侦听端口上,因为我受到 IP 地址的限制。
From my understanding, the problem is that in the https protocol the HOST is not included in the request. So when the request reaches the server, apache just uses the first match on the IP and port the connection was received on because it does not know the domain it was requested from.
根据我的理解,问题是在 https 协议中,请求中不包含 HOST。因此,当请求到达服务器时,apache 只使用接收连接的 IP 和端口上的第一个匹配项,因为它不知道请求来自哪个域。
The only work around for this is to have a different IP for each domain, or a different port.
唯一的解决方法是为每个域使用不同的 IP 或不同的端口。
Unfortunately you are out of luck using https with a wildcard domain setup, I don't believe there is anyway to get it to work.
不幸的是,您在使用 https 和通配符域设置时运气不佳,我认为无论如何都无法使其正常工作。

