【发布时间】:2021-10-21 12:50:19
【问题描述】:
我使用反向代理来显示子域的后端服务器内容。 subdomain.mydomain.com(服务器 A)应显示 IP 为 123.123.123.123 端口 1111 的服务器(服务器 B)的内容。
subdomain.mydomain.com 的虚拟主机(服务器 A):
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName subdomain.mydomain.com
SSLEngine on
SecAuditEngine On
RewriteEngine On
SSLProxyEngine on
ProxyPreserveHost On
LogLevel warn
<Directory />
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Location />
ProxyPass https://123.123.123.123:1111
ProxyPassReverse https://123.123.123.123:1111
</Location>
ErrorLog /var/log/apache2/error.log
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLVerifyClient none
SSLVerifyDepth 1
SSLCertificateFile /etc/apache2/cert.site/chain_wildcard_site_combined.crt
SSLCertificateKeyFile /etc/apache2/cert.site/key_wildcard_site.key
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
</IfModule>
123.123.123.123:1111的虚拟主机(服务器B):
<IfModule mod_ssl.c>
<VirtualHost 123.123.123.123:1111>
DocumentRoot /srv/www/site/htdocs
SSLEngine on
RewriteEngine On
SSLProxyEngine on
ProxyPreserveHost On
LogLevel warn
<Location "/">
Require ip 222.222.222.222
</Location>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /srv/www/site/htdocs>
Options -Indexes +FollowSymLinks +MultiViews
DirectoryIndex index.php
AllowOverride None
Require all granted
</Directory>
ErrorLog /srv/www/site/log/error.log
CustomLog /srv/www/site/log/access.log combined
CustomLog /srv/www/site/log/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLVerifyClient none
SSLVerifyDepth 1
SSLCertificateFile /etc/apache2/cert.site/chain_wildcard_site_combined.crt
SSLCertificateKeyFile /etc/apache2/cert.site/key_wildcard_site.key
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
如果我加载 URL: https://subdomain.mydomain.com/dir/
加载成功。
如果我加载 URL(不带斜杠): https://subdomain.mydomain.com/dir
它导致错误页面:ERR_CONNECTION_REFUSED。
EDIT1:
我执行命令:
curl -IL https://subdomain.mydomain.com/dir
我得到了这个结果:
HTTP/1.1 301 Moved Permanently
Date: Mon, 23 Aug 2021 13:45:13 GMT
Server: Apache
Strict-Transport-Security: max-age=15768000; includeSubDomains
Strict-Transport-Security: max-age=15768000; includeSubDomains
Location: https://subdomain.mydomain.com:1111/dir/
Content-Type: text/html; charset=iso-8859-1
curl: (7) Failed to connect to subdomain.mydomain.com port 1111: Connection refused
EDIT2:
我添加了斜杠
<Location />
ProxyPass https://123.123.123.123:1111/
ProxyPassReverse https://123.123.123.123:1111/
</Location>
但我仍然收到 Connection denied 错误。
知道为什么在缺少斜杠时会导致错误吗?
谢谢!
【问题讨论】:
-
https://subdomain.mydomain.com:1111/dir- 此 URL 不应包含:1111端口号。仅此一项就可能导致 ERR_CONNECTION_REFUSED 错误,因为服务器 A 可能只侦听端口 443(也可能是端口 80)。当您从该 URL 中删除端口时,您会得到什么响应? -
谢谢!这是一个错字。我在 OP 中修改了它:subdomain.mydomain.com/dir
标签: apache reverse-proxy mod-proxy