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

发布于 2024-07-29 03:19:26 字数 2057 浏览 10 评论 0原文

我想要实现的目标如下: 我想要有许多子域,例如 abc.domain.com 重定向到 www.domain.com/something?subdomain=abc 等网址,

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

这是我的 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]

这个设置运行良好(当然,如果您认为可以改进它,请告诉我)。

我的主要问题是当我尝试设置 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 - 我得到的响应是主页,但无论我在子域末尾附加什么,我都会得到相同的响应。 看来重写的反应不太好。

任何帮助将不胜感激,或者如果您可以分享如何设置反向代理、重写、通配符子域和 SSL,

谢谢,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听你说爱我 2024-08-05 03:19:26

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

据我了解,问题在于 https 协议中 HOST 未包含在请求中。 因此,当请求到达服务器时,apache 仅使用接收连接的 IP 和端口上的第一个匹配项,因为它不知道请求的域。

解决此问题的唯一方法是为每个域使用不同的 IP 或不同的端口。

不幸的是,您不走运使用带有通配符域设置的 https,我不相信无论如何都可以让它工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文