views:

1031

answers:

1

Hey All, 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

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)

This is my DNS setup

*.domain.com.   14400    A  111.111.11.1

This is my virtual host configuration for 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://

This is my virtual host configuration for 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. 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

Thanks,

A: 

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.

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.

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

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.

Mike