我被要求在Apache上的localhost上使用自签名证书设置HTTPS,但我实际上如何做到这一点?我完全不知道。
当前回答
为此我使用ngrok (https://ngrok.com/)。 Ngrok是一个命令行工具,用于为本地主机创建隧道。它同时创建http和https连接。 下载完成后,需要执行以下命令:
ngrok http 80
(在版本2中,语法是:ngrok http 80。在版本2中,任何端口都可以通过隧道。)
几秒钟后,它会给出两个url:
http://a_hexadecimal_number.ngrok.com
https://a_hexadecimal_number.ngrok.com
现在,两个url都指向localhost。
其他回答
我想在@CodeWarrior的非常好的回答中添加一些东西,这在Chrome上完美地工作,但对于Firefox需要额外的步骤。
由于Firefox不支持默认情况下Windows提供的CA证书,您需要继续:config,向下滚动到security.enterprise_root。Enabled并将其更改为true。
现在,您的证书在Firefox上也应该是有效的。
当然,这仅用于开发目的,因为ssl信任是一个关键的安全问题,只有在知道其影响时才更改此设置。
这个HowTo for CentOS很简单,只花了大约5分钟:https://wiki.centos.org/HowTos/Https
我不会在这里详细介绍每一步,但主要步骤如下:
1)。安装apache的openssl模块(如果尚未安装)
2)。生成自签名证书
—此时,您应该能够成功访问https://localhost
3)。如果需要,可以设置一个虚拟主机
为了保护发送到web服务器和从web服务器发送的信息的安全,启用客户端和服务器之间的通信加密是一个好主意。这通常称为SSL。
因此,让我们在Apache2上使用自签名证书设置HTTPS。我将列出你应该遵循的步骤:
在你的机器上安装apache2 web server。对于linux机器,打开终端并输入
Sudo apt-get安装apache2
安装成功后,可以通过命令检查apache2服务的状态
Sudo服务apache2状态
它应该输出
导航到浏览器并输入
http://localhost:80
验证您获得了apache2的默认页面,如下所示。
为了加密web连接,我们需要CA(证书颁发机构)的证书,或者我们可以使用自签名证书。让我们使用以下命令创建一个自签名证书。
Openssl req -x509 -newkey rsa:2048 -keyout mykey。输入mycert。Pem -days 365 -nodes
请按如下所示填写相关信息。
mykey。Key和mycert。Pem应在当前工作目录中创建。
如果我们把证书和密钥移到一个公共的地方,apache2 web服务器就很容易找到它们了。让我们执行下面的命令
Sudo cp mycert。pem /etc/ssl/certs
Sudo cp mykey。关键/etc/ssl/private
让我们在服务器上启用SSL模式
Sudo a2enmod SSL
它应该像这样输出
让我们将apache2配置为使用上面生成的自签名证书和密钥。
sudo vi /放开
请找到这两行,并用您的证书和密钥路径替换它们。
最初的
最后
启用站点
cd /etc/apache2/sites-available / Sudo a2ensite default-ssl.conf
重新启动apache2服务
Sudo服务apache2重启
在HTTPS上验证apache2 web服务器。再次打开浏览器并输入
https://localhost:443
它应该输出如下内容,并警告您即将查看的页面不安全,因为我们已经使用自签名证书配置了服务器。
恭喜您已经将apache2配置为HTTPS端点,现在单击高级—>添加例外—>确认安全例外,您将再次看到默认页面。
我刚刚尝试了这一点-我需要在Windows上的本地主机Apache上测试一些开发代码。这比想象中要困难得多。但下面这些步骤在经历了多次拉扯之后还是有效的……
我发现我的Apache安装自带openssl.exe,这很有帮助。如果你没有副本,你需要下载。我的拷贝在Apache2\bin文件夹中,这就是我在下面引用它的方式。
步骤:
Ensure you have write permissions to your Apache conf folder Open a command prompt in Apache2\conf folder Type ..\bin\openssl req -config openssl.cnf -new -out blarg.csr -keyout blarg.pem You can leave all questions blank except: PEM Passphrase: a temporary password such as "password" Common Name: the hostname of your server When that completes, type ..\bin\openssl rsa -in blarg.pem -out blarg.key Generate your self-signed certificate by typing: ..\bin\openssl x509 -in blarg.csr -out blarg.cert -req -signkey blarg.key -days 365 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 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 In the SSL config httpd-ssl.conf I had to update the following lines: 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" Restart Apache. Try loading https://localhost/ in your browser.
希望你能做到这一步。请随时更新这篇文章与任何其他有用的信息。
(截图由Neil Obremski和他的有用文章提供——尽管现在已经过时了。)
博士tl;
ssh -R youruniquesubdomain:80:localhost:3000 serveo.net
您的本地环境可以从https://youruniquesubdomain.serveo.net访问
Serveo是最好的
没有注册。 没有安装。 HTTPS。 全球范围内访问。 您可以指定自定义修复子域。 你可以自己托管它,这样你就可以使用自己的域名,即使服务宕机,你也可以为未来做准备。
当我发现这项服务时,我简直不敢相信。它提供了一切,而且是最容易使用的。如果有这样一个简单无痛的工具可以解决所有问题……
推荐文章
- CFNetwork SSLHandshake iOS 9失败
- HTTPS和SSL3_GET_SERVER_CERTIFICATE:证书验证失败,CA is OK
- c#忽略证书错误?
- 如何找出如果你使用HTTPS没有$_SERVER['HTTPS']
- 最好的方法在asp.net强制https为整个网站?
- 127.0.0.1和localhost之间的区别是什么
- 如何允许本地主机上的Apache使用HTTPS ?
- XAMPP -端口80被PID 4的“无法打开进程”使用!12
- 如何让Chrome允许混合内容?
- 无法识别的SSL消息,明文连接?异常
- 为什么对Apache提供的文本文件使用deflate而不是gzip ?
- OAuth:如何测试本地url ?
- PHP获取网站URL协议- http vs https
- 自动HTTPS连接/重定向使用node.js/express
- Apache从非WWW重定向到WWW