如何在本地主机上允许 Apache 使用 HTTPS? [英] How do I allow HTTPS for Apache on localhost?

查看:30
本文介绍了如何在本地主机上允许 Apache 使用 HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求在本地主机上的 Apache 上使用自签名证书设置 HTTPS,但我实际上如何做到这一点?我完全不知道.

I was asked to set up HTTPS with a self-signed cert on Apache on localhost, but how do I actually do that? I have no idea at all.

推荐答案

我刚刚尝试了这个 - 我需要在我的 localhost Apache on Windows 上测试一些开发代码.这比它应该的要困难得多.但这里是经过多次拔毛后设法工作的步骤......

I've just attempted this - I needed to test some development code on my localhost Apache on Windows. This was WAAAY more difficult than it should be. But here are the steps that managed to work after much hairpulling...

我发现我的 Apache 安装附带了 openssl.exe,这很有帮助.如果您没有副本,则需要下载它.我的副本位于 Apache2\bin 文件夹中,这是我在下面引用它的方式.

I found that my Apache install comes with openssl.exe which is helpful. If you don't have a copy, you'll need to download it. My copy was in Apache2\bin folder which is how I reference it below.

步骤:

  1. 确保您对 Apache conf 文件夹具有写入权限
  2. Apache2\conf 文件夹中打开命令提示符
  3. 输入
    ..\bin\openssl req -config openssl.cnf -new -out blarg.csr -keyout blarg.pem
  4. 您可以将所有问题留空,除了:

  1. Ensure you have write permissions to your Apache conf folder
  2. Open a command prompt in Apache2\conf folder
  3. Type
    ..\bin\openssl req -config openssl.cnf -new -out blarg.csr -keyout blarg.pem
  4. You can leave all questions blank except:

  • PEM 密码:临时密码,例如password"
  • 通用名称:服务器的主机名

完成后,输入
..\bin\openssl rsa -in blarg.pem -out blarg.key

键入以下内容生成您的自签名证书:
..\bin\openssl x509 -in blarg.csr -out blarg.cert -req -signkey blarg.key -days 365

Generate your self-signed certificate by typing:
..\bin\openssl x509 -in blarg.csr -out blarg.cert -req -signkey blarg.key -days 365

打开 Apache 的 conf\httpd.conf 文件并确保 SSL 模块已启用 - 此行的开头不应有哈希:
LoadModule ssl_module modules/mod_ssl.so

Open Apache's conf\httpd.conf file and ensure SSL module is enabled - there should be no hash at the start of this line:
LoadModule ssl_module modules/mod_ssl.so

某些 Apache 安装将 SSL 配置放在单独的文件中.如果是,请确保包含 SSL conf 文件.就我而言,我不得不取消注释这一行:
包括conf/extra/httpd-ssl.conf

Some Apache installations place the SSL config in a separate file. If so, ensure that the SSL conf file is being included. In my case I had to uncomment this line:
Include conf/extra/httpd-ssl.conf

在 SSL 配置 httpd-ssl.conf 中,我必须更新以下几行:

In the SSL config httpd-ssl.conf I had to update the following lines:

  • 更新
    SSLSessionCache "shmcb:C:\Program Files (x86)\Zend\Apache2/logs/ssl_scache(512000)"

    SSLSessionCache "shmcb:C:/Progra\~2/Zend/Apache2/logs/ssl_scache(512000)"
    (路径中的括号混淆了模块,所以我们需要对它们进行转义)
  • DocumentRoot - 将此设置为您的网络文件的文件夹
  • ServerName - 服务器的主机名
  • SSLCertificateFile "conf/blarg.cert"
  • SSLCertificateKeyFile "conf/blarg.key"
  • Update
    SSLSessionCache "shmcb:C:\Program Files (x86)\Zend\Apache2/logs/ssl_scache(512000)"
    to
    SSLSessionCache "shmcb:C:/Progra\~2/Zend/Apache2/logs/ssl_scache(512000)"
    (The brackets in the path confuse the module, so we need to escape them)
  • DocumentRoot - set this to the folder for your web files
  • ServerName - the server's hostname
  • SSLCertificateFile "conf/blarg.cert"
  • SSLCertificateKeyFile "conf/blarg.key"

重启 Apache.

希望你做到了这一步.请随时使用任何其他有用的信息更新此帖子.

Hopefully you made it this far. Feel free to update this post with any other helpful info.

(截图由 Neil Obremski 和他有用的文章提供 - 虽然现在已经很成熟了 -最新.)

(Screenshots courtesy of Neil Obremski and his helpful article - although now quite out-of-date.)

这篇关于如何在本地主机上允许 Apache 使用 HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆