【问题标题】:Use Apache To Run SSL On Port 8980 Specifically使用 Apache 在 8980 端口上运行 SSL
【发布时间】:2021-07-22 16:58:30
【问题描述】:

我有一个 Web 服务,我可以通过完全按原样输入以下 URL 来访问它(一个字符一个字符):

http://10.115.252.127:8980/opennms/login.jsp

网站文件来自 /opt/opennms/jetty-webapps/opennms/

我的目标是使用 Apache (httpd.conf) 强制任何到此 URL 的流量使用 SSL 而不再使用 HTTP。

  1. 我已成功安装 SSL 证书,没有任何问题。
  2. 我已配置 VirtualHost 指令将端口 80 重定向到 443
  3. 只有 /var/www/html/* 下的站点被成功重定向。

示例:http://10.115.252.127/numbers 成功重定向到 https://10.115.252.127/numbers http://10.115.252.127/charts 成功重定向到https://10.115.252.127/charts

但是,当我输入 URL http://10.115.252.127:8980/opennms/login.jsp 时,它总是作为 HTTP 服务......我如何让它像其他人一样作为 HTTPS 服务?我检查了论坛,所有帖子都假设您将始终重定向端口 80,并且在我解释的场景中没有说明如何使用 SSL。我在端口 3000 http://10.115.252.127:3000/login 上运行的另一个服务也有同样的问题

===从我的 httpd.conf 中提取===

<VirtualHost *:80>
ServerName 10.115.252.127
Redirect permanent / https://10.115.252.127/
</VirtualHost>


<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /etc/httpd/conf/ssl.crt/cert_mtocb2500lbscorp.crt
        SSLCertificateKeyFile /etc/httpd/conf/ssl.key/mtocb2500-lbscorp.key
        ServerName 10.115.252.127
        #Documentroot /var/www/html
</VirtualHost>

【问题讨论】:

  • 如果你输入http://...,它默认为端口80。如果你指定一个端口(http://...:8980),它将在端口8980上做HTTP。所以你必须有Listen 8980和一个@ 987654334@ 块在您的配置中。
  • 嗨@Nic3500,感谢您的回复。我已经尝试过您的建议,但不幸的是,在添加 Listen 8980 时出现错误。 Apache wont start up and says (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:8980。我还尝试创建一个指向/opt/opennms/jetty-webapps/opennms 的符号链接,但浏览器只列出文件并且不执行login.jsp。您能否就&lt;VirtualHost *:8980&gt;block 的确切语法提出建议?
  • 我可能误解了一些细节,让我们仔细检查一下。您当前有 HTTP 端口 80 --redirect--> HTTPS 端口 443。这工作正常。那么你有一些监听 8980 端口的软件(不是 Apache)对吗?你想让https://..../opennms/... 被代理到那个8980 端口。我了解您的要求吗?
  • 嗨@Nic3500 为延迟回复道歉,我想我们可能在不同的时区(我在南非)。根据您上次的评论,您已经 100% 理解了该场景。 Apache/Web 不是我的强项,但我在我的 8980 虚拟标签中尝试了各种配置。目前我的设置如下所示,但我永远无法将其设置为 https://...../opennms/... :( ProxyPass 127.0.0.1:8980/opennms ProxyPassReverse @ 987654329@

标签: apache redhat opennms


【解决方案1】:

根据您对我理解的确认,您可以执行以下操作:

############################################################################
Listen 80

# All connections on port 80 are redirected to port 443
<VirtualHost *:80>
    ServerName www.example.com
    CustomLog "logs/80_access.log" combined
    ErrorLog "logs/80_error.log"

    Redirect permanent / https://www.example.com
    
    # No documentRoot, no content
</VirtualHost>

############################################################################
Listen 443

# All URI are answered from the documentRoot directory
# EXCEPT /openms, which is proxied to :8980
<VirtualHost *:443>
    ServerName www.example.com

    # temporary, remove when tests done
    LogLevel debug
    CustomLog "logs/443_access.log" combined
    Errorlog "logs/443_error.log"

    SSLEngine on
    SSLCertificateFile /etc/httpd/conf/ssl.crt/cert_mtocb2500lbscorp.crt
    SSLCertificateKeyFile /etc/httpd/conf/ssl.key/mtocb2500-lbscorp.key

    # For your redirection to 8980
    ProxyPass           /opennms    "https://www.example.com:8980/"
    ProxyPassReverse    /opennms    "https://www.example.com:8980/"

    documentRoot "/yourdir/apache/htdocs"
    DirectoryIndex index.html
</VirtualHost>

先决条件

  • 您必须加载代理模块
  • 你必须加载重写模块
  • 端口 8980 链接到其他一些软件。 Apache 不处理 8980。

【讨论】:

  • 谢谢@Nic3500,这帮助很大。我现在让 opennms 重定向到 https。我只需要解决为什么它不执行 .jsp 页面,但我会将其视为一个单独的问题。感谢所有的耐心和帮助
猜你喜欢
  • 2015-05-12
  • 1970-01-01
  • 2013-09-16
  • 2015-11-04
  • 2019-11-16
  • 2019-01-11
  • 2015-04-21
  • 2017-12-25
  • 2011-01-28
相关资源
最近更新 更多