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 / 问题 / 43458
Accepted
Shalom Craimer
Shalom Craimer
Asked: 2009-07-21 20:53:57 +0800 CST2009-07-21 20:53:57 +0800 CST 2009-07-21 20:53:57 +0800 CST

在 Apache 上使用自签名证书设置 https

  • 772

我正在尝试使用自签名证书在 Apache 上设置 HTTPS。但是我没有显示页面,而是收到了一堆奇怪的错误。每个浏览器都有不同的错误!

从铬:

错误 2 (net::ERR_FAILED):未知错误。

从火狐:

SSL 收到超过最大允许长度的记录。(错误代码:ssl_error_rx_record_too_long)

我按照http://slacksite.com/apache/certificate.php以及其他大约 4 个指南中详述的步骤进行操作。它们都差不多,但都给出相同的结果。所以我一定做错了什么。

简而言之,这就是我所做的:

  • 生成服务器密钥:

    openssl genrsa -des3 -out server.key 1024

  • 生成企业社会责任:

    openssl req -new -key server.key -out server.csr

[在生成请求时,我小心地将我的实际主机名输入为“通用名称(例如,您的姓名或服务器的主机名)”]

  • 从密钥中删除密码:

    cp server.key server.key.org
    openssl rsa -in server.key.org -out server.key

  • 自签名证书:

    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

  • 将 apache 配置为指向这些文件,并使用这些证书。

有任何想法吗?

更新:这是我的虚拟主机配置:

LoadModule ssl_module modules/mod_ssl.so
Listen 443
#   Some MIME-types for downloading Certificates and CRLs
#
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl
SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout  300
SSLMutex default
SSLRandomSeed startup file:/dev/urandom  256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin

## Virtual host to redirect to HTTPS
<VirtualHost *:80>
    ServerName mail.craimer.org
    Redirect permanent / https://mail.craimer.org:443
</VirtualHost>

##
## SSL Virtual Host Context
##

<VirtualHost mail.craimer.org:443>
    ServerName mail.craimer.org
    DocumentRoot "/usr/share/roundcubemail/trunk/roundcubemail/"

         ErrorLog logs/ssl_error_log
         TransferLog logs/ssl_access_log
         LogLevel warn

         SSLEngine on

         SSLProtocol all -SSLv2

         SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW

         SSLCertificateFile /etc/httpd/conf/ssl/server.crt
         SSLCertificateKeyFile /etc/httpd/conf/ssl/server.key

         <Files ~ "\.(cgi|shtml|phtml|php3?)$">
                                SSLOptions +StdEnvVars
         </Files>
         <Directory "/var/www/cgi-bin">
                                SSLOptions +StdEnvVars
         </Directory>

    # Deal with broken MSIE
         SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

    CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
apache-2.2 certificate https httpd
  • 6 6 个回答
  • 9812 Views

6 个回答

  • Voted
  1. Dan Carley
    2009-07-22T03:27:20+08:002009-07-22T03:27:20+08:00

    问题更可能在于您的虚拟主机配置。

    通过ssl_error_rx_record_too_long针对 HTTP 资源启动 HTTPS 会话可能会产生错误。比如—— https://host.name:80。

    • 4
  2. Sliff
    2009-07-21T23:28:33+08:002009-07-21T23:28:33+08:00

    我过去使用的方法与您详述的方法略有不同。下面的说明最初是我在查看如何设置 ssl 时发现的这篇文章中的详细说明:通过 Active Directory (SSPI) 在 Apache/SSL 上逐步安装 Subversion

    总结一下:

    1. 在 apache\bin 下创建 openssl.conf 并将其内容设置如下:

      [ v3_ca ]
      subjectKeyIdentifier = 哈希
      authorityKeyIdentifier = keyid:always,issuer:always
      基本约束 = CA:true
      [请求]
      默认位 = 1024
      default_keyfile = server.key
      区分名 = req_distinguished_name
      属性 = req_attributes
      x509_extensions = v3_ca  
      string_mask = nombstr
      [ req_distinguished_name ]  
      commonName = 通用名称
      commonName_default = 我的服务器名称
      [请求属性]
    2. 打开命令提示符,导航到 apache\bin 并运行以下命令:

      openssl req -config openssl.conf -new -out server.csr

    3. 出现提示时输入密码短语,然后再次验证。

    4. 然后将提示您输入通用名称 [我的服务器名称]。输入机器名称

    5. 接下来使用以下命令从私钥中删除密码(注意这可能会给出一个关于无法找到 openssl.conf 的警告 - 这可以忽略):

      openssl rsa -in server.key -out server.key

    6. 出现提示时输入以前使用的密码

    7. 接下来使用以下命令创建自签名证书

      `openssl x509 -in server.csr -out server.cert -req -signkey server.key -days 365

    8. 从 apache\bin 文件夹中删除 server.csr 文件。

    9. 将 server.key 和 server.cert 文件从 apache\bin 文件夹复制到 apache\conf 文件夹。

    10. 在文本编辑器中打开 apache\conf\httpd.conf。

    11. 将监听端口指令(可能是监听 80 或监听 8080)更改为端口 443:

      Listen 443

    12. 更改 ServerName 指令以包含端口 443(请注意,这可能会被注释掉,因此如果是,请删除行首的 # 并将 server 替换为您的服务器名称):

      ServerName server:443

    13. 取消注释或添加 mod_ssl 的加载模块指令(这应该存在并注释,因此删除行开头的 #):

      LoadModule ssl_module modules/mod_ssl.so

    14. 为 mod_ssl 添加一个 IfModule 部分(这不应该已经存在,但如果它被覆盖它):

      <IfModule mod_ssl.c>
          SSLEngine 开启
          SSLRandomSeed 启动内置
          SSLRandomSeed 连接内置
          SSLPassPhraseDialog 内置
          SSLSessionCache dbm:logs/ssl_scache
          SSLSessionCacheTimeout 300
          SSLMutex 默认
          SSLCertificateFile conf\server.cert
          SSLCertificateKeyFile conf\server.key
      </IfModule>
    15. 重新启动 Apache 服务。通过尝试(并失败)通过 http 连接并尝试(并成功)通过 https 连接来测试配置。

    • 1
  3. Best Answer
    Shalom Craimer
    2010-12-10T23:40:47+08:002010-12-10T23:40:47+08:00

    好吧,由于用户 Jure1873 还没有写出答案,我不能给他应得的荣誉。这是他的解决方案:

    如果你用 替换<VirtualHost mail.craimer.org:443>怎么<virtualhost *:443>办?

    这就是解决方案。事实证明(在撰写本文时)httpd无法支持 HTTPS 的多个虚拟主机,因此到 443 的任何连接都必须定向到单个主机。所以我猜httpd只是默默地拒绝了尝试为 HTTPS 运行虚拟主机的配置。

    哦,不要因为这个“缺失的功能”而指责 apache。这不是他们的错!HTTPS 协议不支持虚拟主机。

    无聊的解释:

    您会看到,当您连接到端口 443 并启动 HTTPS 会话时,所发生的只是安全协商。HTTPS 就是在两点之间建立安全隧道,与 HTTP 无关。只有建立隧道后,数据才会流过。该数据是 HTTP 流。

    这意味着Host:指令(它是 HTTP 的一部分,而不是 HTTPS)只会在构建安全隧道后发送。它是Host:告诉 HTTP 服务器正在访问哪个虚拟主机的标头。但是在 HTTPS 中,我们获得这些信息太晚了:它是在我们必须选择加密密钥之后到达的。

    底线:HTTPS不能根据HTTP主机名选择加密密钥。

    • 1
  4. Milan Karalic
    2009-07-22T04:41:54+08:002009-07-22T04:41:54+08:00

    从 VirtualHost 配置中删除标记。例如。 <IfModule mod_ssl.c > </IfModule> - 删除那些行

    • 0
  5. Prashant Saraswat
    2016-07-28T11:23:39+08:002016-07-28T11:23:39+08:00

    这是发生此错误的另一种情况:

    VirtualHost *:80中定义sites-enabled/000-default.conf。然后定义VirtualHost *:443

    在httpd.conf

    如果您将配置完全移动到其中之一httpd.conf或到000-default.conf它工作。否则,您会在 FireFox 上收到此错误:

    SSL received a record that exceeded the maximum permissible length. (Error code: ssl_error_rx_record_too_long)
    

    chrome上的这个错误:

    This site can’t provide a secure connection
    ... sent an invalid response.
    
    • 0
  6. meglio
    2012-05-20T02:47:26+08:002012-05-20T02:47:26+08:00

    Scraimer,接受的答案是错误的,否则您为什么认为 SSLCertificateFile 指令可以在虚拟主机范围内?证明:http ://httpd.apache.org/docs/current/mod/mod_ssl.html#sslcertificatefile

    使用虚拟主机,您仍然可以将不同的证书文件与基于名称的虚拟主机一起使用。

    我遇到了同样的麻烦,解决方案是在 VirtualHost 指令中放置真实 IP 而不是 *,如下所示:

    NameVirtualHost *:80
    NameVirtualHost *:443
    
    <VirtualHost 127.0.0.1:443>
      ServerName affx.meg
      ...
    </VirtualHost>
    

    PS Hovewer 我不知道它为什么起作用。我只是将此配置作为来自真实服务器的示例,并将其重用于我的设置并且它有效。

    • -1

相关问题

  • 阿帕奇的替代品

  • 如何强制我的网址始终以 www 开头?

  • 在 Linux Xen VPS 上优化 Apache 和 MySQL

  • 您最喜欢的 SSL 证书提供商是什么?[关闭]

  • mod_rewrite 不转发 GET 参数

Sidebar

Stats

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

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

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

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

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

    • 3 个回答
  • Marko Smith

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

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +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