如何通过Apache 2将HTTP请求重定向到自定义端口HTTPS/443?

1tu0hz3e  于 2022-11-16  发布在  Apache
关注(0)|答案(1)|浏览(393)

我正在尝试为一个特定的用例配置apache 2。一个旧的Web服务器只能在HTTP端口8788上运行。我想把它放在一个apache反向代理(Debian)后面,这将确保与客户端的交换加密,并在HTTP/端口8788上向Web服务器发出请求。
反向代理已经为其他Web服务器工作,我更改了www.example.com的DNSoldserver.example.com,使其指向反向代理IP地址。
http://oldserver.example.comhttps://oldserver.example.com的连接工作正常,并显示旧服务器的网页。
但是当我尝试访问http://oldserver.example.com:8788时(我必须通过端口8788保持此访问,因为该链接已发布多年),浏览器重定向到https://oldserver.example.com:8788并显示以下错误:
Secure Connection Failed
在下面的配置文件和日志中,我将反向代理IP地址替换为X.X.X.X;旧服务器的IP地址用Y.Y.Y.Y表示,客户端的IP地址用Z. Z. Z. Z表示。
当我尝试使用wget时,一切似乎都很好:

wget -v http://oldserver.example.com:8788
--2022-09-14 14:36:15--  http://oldserver.example.com:8788/
Resolving oldserver.example.com (oldserver.example.com)... X.X.X.X
Connecting to oldserver.example.com (oldserver.example.com)|X.X.X.X|:8788... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://oldserver.example.com/ [following]
--2022-09-14 14:36:15--  https://oldserver.example.com/
Connecting to oldserver.example.com (oldserver.example.com)|X.X.X.X|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11628 (11K) [text/html]
Saving to: 'index.html'

index.html.3                                        100%[=================================================================================================================>]  11.36K  --.-KB/s    in 0s

2022-09-14 14:36:15 (42.0 MB/s) - 'index.html' saved [11628/11628]

配置文件

/etc/apache 2/sites-可用的/旧的服务器.conf文件:

<VirtualHost *:80 *:8788>
    ServerName oldserver.example.com
    include /etc/apache2/xyz/general.conf
    include /etc/apache2/xyz/redirect-ssl.conf
    ErrorLog ${APACHE_LOG_DIR}/error_oldserver.log
    CustomLog ${APACHE_LOG_DIR}/access_oldserver.log combined
</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost *:443>
            ServerName oldserver.example.com

            ErrorLog ${APACHE_LOG_DIR}/error_oldserver.log
            CustomLog ${APACHE_LOG_DIR}/access_oldserver.log combined

            include /etc/apache2/xyz/general.conf
            include /etc/apache2/xyz/ssl.conf
            include /etc/apache2/xyz/revproxy.conf
            ProxyPass / http://Y.Y.Y.Y:8788/
            ProxyPassreverse / http://Y.Y.Y.Y:8788/
    </Virtualhost>
</IfModule>

/etc/apache 2/xyz/通用配置文件:

ServerAdmin system@example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Protocols h2 http/1.1
DocumentRoot /var/www/html
ErrorDocument 500 https://reverseproxy.example.com/
ErrorDocument 503 https://reverseproxy.example.com/

/etc/apache 2/xyz/重定向到ssl.conf文件中的所有文件:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

/etc/apache 2/xyz/revproxy.conf文件中指定的文件类型:

ProxyPreserveHost On
ProxyRequests Off
SSLProxyEngine on

/etc/apache 2/xyz/ssl.conf文件中指定的文件类型:

#####▒| SSL #####

SSLEngine on
Header always set Strict-Transport-Security "max-age=15768000"

SSLCertificateFile      /etc/ssl/wildcard.example.com.crt
SSLCertificateKeyFile   /etc/ssl/wildcard.example.com.key

<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

日志

奇怪的是,在反向代理上,我在/var/log/apache 2/error_oldserver. log文件中什么都没有,但我在/var/log/apache 2/error. log文件中找到了连接的跟踪信息:

error.log:[Wed Sep 14 14:43:53.497291 2022] [proxy_http:error] [pid 36806:tid 139808714381056] (20014)Internal error (specific information not available): [client Z.Z.Z.Z:51225] AH01102: error reading status line from remote server Y.Y.Y.Y:8788, referer: https://oldserver.example.com/

我无法访问旧服务器的日志。
提前感谢您的帮助。

mrphzbgm

mrphzbgm1#

在同一虚拟主机中添加端口为 *:8788的新块,并在虚拟主机文件中的同一块中添加LISTEN 8788。端口应从安全组打开。

<VirtualHost *:443>
ServerName oldserver.example.com
DocumentRoot /var/www/oldserver.example.com/public

<Directory /var/www/oldserver.example.com>
        Options FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

      ErrorLog /var/www/oldserver.example.com/error.log
      CustomLog /var/www/oldserver.example.com/access.log combined

SSLEngine on
SSLCertificateKeyFile /SSL Certificate path/xxx.pem
SSLCertificateFile /SSL Certificate path/xxx.pem
SSLCertificateChainFile /SSL Certificate path/xxx.pem

</VirtualHost>

LISTEN 8788
<VirtualHost *:8788>
ServerName oldserver.example.com
DocumentRoot /var/www/oldserver.example.com/public

<Directory /var/www/oldserver.example.com>
        Options FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

SSLEngine on
SSLCertificateKeyFile /SSL Certificate path/xxx.pem
SSLCertificateFile /SSL Certificate path/xxx.pem
SSLCertificateChainFile /SSL Certificate path/xxx.pem

</VirtualHost>

相关问题