gpt4 book ai didi

Apache、Tomcat 和 SSL : ProxyPass and ProxyPassReverse

转载 作者:行者123 更新时间:2023-11-28 22:39:28 25 4
gpt4 key购买 nike

我在配置 Apache、Tomcat 和 SSL 时遇到问题,情况是这样的:

我有一个 Apache Web 服务器,正常运行和工作(但是,我可以访问这个服务器,只需键入:

https://example.com

另外,在这台主机上,我有一个 Tomcat 在端口 8080 (HTTP) 上运行并且工作正常;我创建了一个迷你网络应用程序,其中的文件位于“测试”目录中,我可以输入:

http://example.com:8080/test

(我知道Apache运行在80端口,Tomcat运行在8080端口)

我想做的是用户可以使用 HTTPS 通过 Apache 访问“测试”(在 Tomcat 上运行),我的意思是:

https://example.com/test

但是当我访问这个链接时出现这个:

Page not found

当我使用 HTTP 访问时 http://example/test 有效,但我需要它是 HTTPS。

我还在/etc/httpd/conf.d/vhost.conf中创建了一个文件config,内容是这样的:

<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html
Redirect permanent / https://example.com/
</VirtualHost>

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

SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem

SSLProxyEngine on
ProxyPass /test http://xxx.xxx.xxx.xxx:8080/test
ProxyPassReverse /test http://xxx.xxx.xxx.xxx:8080/test
</VirtualHost>

xxx.xxx.xxx.xxx为网站IP。

当我访问网站 https://example.com/(使用 HTTPS)时,我遇到了这个问题(我在网站中使用了网络应用程序):

Security Overview

我使用证书 Let's Encrypt(在上图中)。

我正在使用 Apache/2.4.33 (Amazon) 和 Tomcat 8.5.29

有谁知道为什么或如何解决这个问题?提前谢谢大家。

日志文件:

访问日志

yyy.yyy.yyy.yyy - - [01/Jul/2018:06:42:29 +0000] "GET /test HTTP/1.1" 301 245 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
::1 - - [01/Jul/2018:06:42:51 +0000] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.33 (Amazon) OpenSSL/1.0.2k-fips PHP/7.0.30 (internal dummy connection)"

error_log - 空

ssl_access_log

yyy.yyy.yyy.yyy - - [01/Jul/2018:06:42:29 +0000] "GET /test HTTP/1.1" 404 206
yyy.yyy.yyy.yyy - - [01/Jul/2018:06:42:29 +0000] "GET /test HTTP/1.1" 404 206
yyy.yyy.yyy.yyy - - [01/Jul/2018:06:42:49 +0000] "-" 408 -
yyy.yyy.yyy.yyy - - [01/Jul/2018:06:42:49 +0000] "-" 408 -
yyy.yyy.yyy.yyy - - [01/Jul/2018:06:42:49 +0000] "-" 408 -
yyy.yyy.yyy.yyy - - [01/Jul/2018:06:42:49 +0000] "-" 408 -

ssl_request_log

[01/Jul/2018:06:42:29 +0000] yyy.yyy.yyy.yyy TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 "GET /test HTTP/1.1" 206
[01/Jul/2018:06:42:29 +0000] yyy.yyy.yyy.yyy TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 "GET /test HTTP/1.1" 206
[01/Jul/2018:06:42:49 +0000] yyy.yyy.yyy.yyy TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 "-" -
[01/Jul/2018:06:42:49 +0000] yyy.yyy.yyy.yyy TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 "-" -
[01/Jul/2018:06:42:49 +0000] yyy.yyy.yyy.yyy TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 "-" -
[01/Jul/2018:06:42:49 +0000] yyy.yyy.yyy.yyy TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 "-" -

ssl_error_log - 空

yyy.yyy.yyy.yyy = 我机器的IP

最佳答案

代码有4个问题

首先端口有问题。Https 在端口 443 上工作,http 在 端口 80 上工作。 p>

 <VirtualHost *:443> 
ServerName www.example.com
DocumentRoot /var/www/html
###Remove this redirection line to move it in separate virtual host listening to port 80
Redirect permanent / https://example.com/
SSLProxyEngine on
ProxyPass /test http://xxx.xxx.xxx.xxx:8080/test
ProxyPassReverse /test http://xxx.xxx.xxx.xxx:8080/test
</VirtualHost>

其次:没有打开SSLProxyEngine,以便代理传递代理反向传递适用于https 连接。

第三:去掉本虚拟主机的https重定向规则到新虚拟主机,需要新建一个80端口的新虚拟主机,其中应该有重定向规则,其中所有 http 连接永久重定向到 https。

Redirect permanent / https://example.com/

第四:下面还要加上所有的虚拟主机

ServerName example.com 
ServerAlias www.example.com

关于Apache、Tomcat 和 SSL : ProxyPass and ProxyPassReverse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51120325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com