简体   繁体   English

在Apache 2.2.3上设置通配符子域(带有反向代理)

[英]Setting up Wildcard subdomain (with reverse proxy) on apache 2.2.3

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 我要实现的目标如下:我希望将许多子域(例如abc.domain.com)重定向到网址(例如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. 由于我要重定向到完全限定的域,因此需要使用反向代理来避免在浏览器中更改URL。 (using the [P] Flag and turning on the mod_proxy module and some other modules) (使用[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}$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). 此设置运行良好(当然,请告诉我您是否可以改进它)。

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}$1          [C]
    RewriteRule   ^([^.]+)\.domain\.com(.*) https://www.domain.com/something?subdomain=$1 [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. 每当我致电https://abc.domain.com时 ,我得到的响应就是主页,但是无论我在子域末尾附加什么内容,我都会得到相同的响应。 It's like the rewrite isn't responding well. 就像重写没有很好地响应。

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, 谢谢,

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. 据我了解,问题在于在https协议中,主机中未包含请求。 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. 因此,当请求到达服务器时,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与通配符域设置一起使用,我不认为有任何方法可以使它正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM