我的 tomcat 在我的 linux 机器上独立运行在端口 7778 上。我已经将 apache 配置为在端口 443 上的 ssl 上运行。
我的 httpd.conf 如下:
Listen 80
<VirtualHost *:80>
ServerName www.domain.com
Redirect / https://www.example.com
</VirtualHost> -->
ProxyPass / http://localhost:7778/website
ProxyPassReverse / http://localhost:7778/website
我的 ssl.conf 如下:
Listen 443
<VirtualHost _default_:443>
SSLEngine on
SSLCertificateFile /path/to/certificate/file
SSLCertificateKeyFile /path/to/key
</VirtualHost>
我的 server.xml 连接器如下:
<Connector port="7778" protocol="HTTP/1.1"
proxyName="www.domain.com" proxyPort="80" />
问题是我的 Apache 无法重定向到 7778 端口上的 Tomcat,并给出 503 错误。
最佳答案
两步:
1首先确认你的Tomcat没问题。
确保您可以连接到 http://localhost:7778/website并获得预期的响应。
然后,为了代理支持修改您的连接器:
<Connector port="7778" protocol="HTTP/1.1" proxyName="www.example.com" proxyPort="80" />
2 修复您的 Apache 配置
这里我假设:
- 当你尝试http://www.example.com你被重定向到 https://www.example.com
当你尝试 https://www.example.com你从 Tomcat 得到响应
Listen 80 <VirtualHost *:80> ServerName www.example.com ServerAlias example.com CustomLog "logs/80_access.log" combined ErrorLog "logs/80_error.log" Redirect / https://www.example.com </VirtualHost> <VirtualHost *:443> ServerName www.example.com ServerAlias example.com # While debugging LogLevel debug CustomLog "logs/443_access.log" combined ErrorLog "logs/443_error.log" SSLEngine On SSLCertificateFile /path/to/certificate/file SSLCertificateKeyFile /path/to/key # Proxy to Tomcat ProxyRequests Off ProxyPass / http://localhost:7778/website ProxyPassReverse / http://localhost:7778/website </VirtualHost>
您可能需要调整的内容
- 日志文件目录
- 证书文件目录
- LogLevel,一旦工作就移除 Debug模式
- 确保加载了所需的模块。
apachectl -t
会在您遗漏任何内容时通知您。
关于apache - 将 Apache ssl 端口 443 转发到 Tomcat http 端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53333984/