AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1003526
Accepted
user549144
user549144
Asked: 2020-02-19 05:09:57 +0800 CST2020-02-19 05:09:57 +0800 CST 2020-02-19 05:09:57 +0800 CST

如果用户使用http上的443端口访问网站,如何关闭连接?

  • 772

如果用户访问http://example.com:443之类的网站,我如何给用户一个连接重置错误,而不是给出以下错误:

错误的请求

您的浏览器发送了此服务器无法理解的请求。
原因:您对启用 SSL 的服务器端口使用纯 HTTP。
请改用 HTTPS 方案访问此 URL。

上面的错误是 Apache 提供给我不想要的用户的。相反,我只想停止连接,而不是给出文本响应。这可能吗,应该是,因为很多网站都有这个功能。提前致谢。(此外,我自己无法尝试任何事情,因为我不知道它是如何工作的,所以如果可以的话,我可以自己实现它)。

在某种程度上类似,但无论如何都没有回答我的问题: Serving port 443 over http 创建 400 Bad Request Error 而不是 redirect,但提到:“如果您尝试与其他服务器进行此类请求,那么他们将关闭连接而不会出现任何错误完全挂起或者只是挂起,因为他们仍然希望从客户端获得 TLS 握手” ,所以我的问题是如果用户访问http://example.com:443如何关闭连接。

以防万一:

请注意,当用户访问 http:// 而不是 https:// 上的端口 443 时,我想关闭连接。我不希望 apache 显示错误请求消息。我想关闭连接,因为有人提到无法将 http:// 上的 443 重定向到 https://。如果有任何方法可以做到这一点,请告诉我(除了 HSTS,我不愿意信任)。我认为这将使用防火墙来完成(不确定)。我也见过 cPanel 这样做,但我没有将 cPanel 用于其他目的,所以请不要要求我这样做。

还:

除非您修改 Apache 的源代码,否则无法更改 400 bad request 页面,因此无法从 http 重定向到 https。我不认为我被允许修改 Apache 的源代码。

我还看到运行curl http://www.google.com:443说curl: (52) Empty reply from server,所以发送一个空回复应该足以停止连接对吧?我不知道。但也许是的,如果是这样,怎么办?(如果有不同的连接断开方法,请不要回答这个问题)。

需要明确的是:我要求的是sudo ufw deny out 443 http(可能无效)之类的东西。

ubuntu connection apache-2.4
  • 2 2 个回答
  • 301 Views

2 个回答

  • Voted
  1. Jason Cotman
    2020-02-28T00:29:08+08:002020-02-28T00:29:08+08:00

    有趣的。像这样的东西怎么样:

    <VirtualHost *:443>
        <Location />
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
        </Location>
    

    这将拒绝除 localhost 之外的任何端口 443 的流量。

    但实际上我认为您可能想要做的(?)只是将所有 http 请求重定向到 https。重定向后 443 将是多余的。

    • 0
  2. Best Answer
    user549144
    2021-01-26T04:51:59+08:002021-01-26T04:51:59+08:00

    我在 Apache 源代码目录中编辑了一个文件./modules/ssl/ssl_engine_kernel.so。

    在该文件中,您可以找到一行内容:

        if (sslconn->non_ssl_request == NON_SSL_SET_ERROR_MSG) {
            apr_table_setn(r->notes, "error-notes",
                           "Reason: You're speaking plain HTTP to an SSL-enabled "
                           "server port.<br />\n Instead use the HTTPS scheme to "
                           "access this URL, please.<br />\n");
    
            /* Now that we have caught this error, forget it. we are done
             * with using SSL on this request.
             */
            sslconn->non_ssl_request = NON_SSL_OK;
    
            return HTTP_BAD_REQUEST;
        }
    

    请改用 HTTPS 方案访问此 URL,请.....`。

    将其更改为:

        if (sslconn->non_ssl_request == NON_SSL_SET_ERROR_MSG) {
            /*
            apr_table_setn(r->notes, "error-notes",
                           "Reason: You're speaking plain HTTP to an SSL-enabled "
                           "server port.<br />\n Instead use the HTTPS scheme to "
                           "access this URL, please.<br />\n");
            */
            /* Now that we have caught this error, forget it. we are done
             * with using SSL on this request.
             */
            sslconn->non_ssl_request = NON_SSL_OK;
    
            return apr_pstrcat(NULL);
        }
    

    然后,重新编译 Apache。你应该很好:)

    • 0

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve