将子域名的请求重定向到服务器/路径

将子域名的请求重定向到服务器/路径

目前,我们有两个 Web 服务器,第一个直接处理来自 domain1.com 的请求。我正在尝试部署另一个 Web 服务器,它将处理来自 sub.domain2.com 的请求。由于我们的网络中没有 DNS 服务器,所以我必须让第一个 Web 服务器处理所有请求并将其转发到适当的 Web 服务器(即第二个 Web 服务器)。第二个 Web 服务器将托管 wordpress,并将安装在 Web 服务器的非根路径即 /wordpress 上,并且还将安装 SSL 证书。我一直在尝试让它工作,但没有成功,我当前的配置如下:

<VirtualHost *:80>
    ServerName www.domain1.com
    DocumentRoot "D:/Apache2.2/htdocs"
    <Directory "D:/Apache2.2/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog "logs/www.domain1.com -error.log"
    CustomLog "logs/www.domain1.com-access.log" common
    ResinConfigServer 10.0.xx.1 6800
    <Location />
    SetHandler caucho-request
    </Location>
</VirtualHost>

<VirtualHost *:80>
ServerName sub.domain2.com
Redirect / https://sub.domain2.com/
</VirtualHost>

<VirtualHost *:443>
ServerName sub.domain2.com
ProxyRequests Off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>
SSLProxyEngine On
SSLProxyCheckPeerCN on
SSLProxyCheckPeerExpire on
SSLEngine on
SSLCertificateFile "D:\Apache2.2\ssl.pem"
SSLCertificateKeyFile "D:\Apache2.2\ssl.key"
SSLCACertificateFile "D:\Apache2.2\ssl.crt"

ProxyPreserveHost on

ProxyPass /wordpress https://10.0.xx.2:443/wordpress
ProxyPassReverse /wordpress https:// 10.0.xx.2:443/wordpress


ProxyPass / https://10.0.xx.2:443/wordpress
ProxyPassReverse / https://10.0.xx.2:443/wordpress

<Location />
    Order allow,deny
    Allow from all
</Location>
</VirtualHost>

如果我尝试按如下方式进行配置,它可以工作,但它会将链接重定向到 10.0.xx.2 而不是 sub.domain2.com

<VirtualHost *:80>
    ServerName sub.domain2.com
    DocumentRoot "D:/Apache2.2/htdocs"
    <Directory "D:/Apache2.2/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog "logs/sub.domain2.com-error.log"
    CustomLog "logs/sub.domain2.com-access.log" common
    ProxyPass / http://10.0.xx.2/wordpress/
</VirtualHost>

WordPress 的 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(sub.)?domain2.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(sub.)?domain.com$
RewriteRule ^(/)?$ wordpress/index.php [L] 
</IfModule>

相关内容