在Apache 2.2.3上设置通配符子域(带有反向代理) [英] Setting up Wildcard subdomain (with reverse proxy) on apache 2.2.3

查看:198
本文介绍了在Apache 2.2.3上设置通配符子域(带有反向代理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现的目标如下: 我希望将许多 abc.domain.com 子域重定向到 www.domain.com/something?subdomain=abc

What I am trying to achieve is the following: I want to have numerous subdomains such as abc.domain.com redirect to a url such as www.domain.com/something?subdomain=abc

由于我将重定向到完全限定的域,因此我需要使用反向代理来避免在浏览器中更改URL. (使用[P]标志并打开mod_proxy模块和其他一些模块)

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)

这是我的DNS设置

*.domain.com.   14400    A  111.111.11.1

这是我针对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}$1          [C]
RewriteRule   ^([^.]+)\.domain\.com(.*) http://www.domain.com/something?subdomain=$1 [P,L]

此设置运行良好(请告诉我您是否可以改进它).

This setup is working fine (Let me know if you think you can improve it of course).

我的主要问题是当我尝试设置https://

My main problem is when I am trying to setup https://

这是我针对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}$1          [C]
    RewriteRule   ^([^.]+)\.domain\.com(.*) https://www.domain.com/something?subdomain=$1 [P,L]

</VirtualHost>

每当我调用 https://abc.domain.com 时-我得到的响应就是首页,但无论我在子域的末尾附加什么内容,我都将得到相同的响应.就像重写反应不佳.

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.

任何帮助将不胜感激,或者您可以共享设置反向代理,重写,通配符子域和SSL的方式

Any help would be appreciated, or if you could share how you'd setup reverse proxy, rewrite, wildcard subdomain and SSL all together

谢谢

推荐答案

我也遇到了同样的问题.我唯一解决的方法是将需要安全连接的不同域放在不同的侦听端口上,因为我受到IP地址的限制.

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.

据我所知,问题在于在https协议中,请求中未包含HOST.因此,当请求到达服务器时,apache只会在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.

唯一的解决方法是为每个域使用不同的IP,或使用不同的端口.

The only work around for this is to have a different IP for each domain, or a different port.

不幸的是,您无法使用带有通配符域设置的https来运气,我不认为有任何办法可以使它正常工作.

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.

这篇关于在Apache 2.2.3上设置通配符子域(带有反向代理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆