我在配置Apache,Tomcat和SSL时遇到麻烦,这是这种情况:
我有一个Apache Web服务器,可以正常运行并正常工作(但是,只要键入以下内容,我就可以访问它:
https://example.com
此外,在此主机中,我有一个Tomcat在端口8080(HTTP)上运行且运行良好;我创建了一个微型Web应用程序,其文件位于“测试”目录中,可以访问键入内容:
http://example.com:8080/test
(我知道Apache在80端口上运行,而Tomcat在8080上运行)
我想做的是让Apache用户可以使用HTTPS访问“测试”(在Tomcat上运行),
https://example.com/test
但是当我访问此链接时,它会出现以下情况:
当我使用HTTP访问http://example/test
时,可以使用HTTPS。
我还在/etc/httpd/conf.d/vhost.conf
中创建了一个文件配置,内容如下:
<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访问网站https://example.com/
时遇到此问题(我使用网站中的Web应用程序):
我使用证书“加密”(在上图中)。
我正在使用Apache / 2.4.33(Amazon)和Tomcat 8.5.29
有人知道为什么或如何解决这个问题吗?预先感谢大家。
日志文件:
access_log
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)"
错误日志-空
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
答案 0 :(得分:1)
代码有4个问题
首先:端口出现问题。Https适用于port 443
,而http适用于port 80
<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 on
,因此代理通过和代理反向通过可用于https连接。
第三步::将https重定向规则从该虚拟主机删除到新主机。您需要为端口80创建一个新虚拟主机,一种重定向规则,其中所有http连接都永久重定向到https。
Redirect permanent / https://example.com/
第四位:还将以下内容添加到所有虚拟主机
ServerName example.com
ServerAlias www.example.com
答案 1 :(得分:0)
结果文件/etc/httpd/conf.d/vhost.conf
:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias 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>