我被要求在Apache上的localhost上使用自签名证书设置HTTPS,但我实际上如何做到这一点?我完全不知道。
当前回答
我想在@CodeWarrior的非常好的回答中添加一些东西,这在Chrome上完美地工作,但对于Firefox需要额外的步骤。
由于Firefox不支持默认情况下Windows提供的CA证书,您需要继续:config,向下滚动到security.enterprise_root。Enabled并将其更改为true。
现在,您的证书在Firefox上也应该是有效的。
当然,这仅用于开发目的,因为ssl信任是一个关键的安全问题,只有在知道其影响时才更改此设置。
其他回答
对于那些使用macOS的人来说,这是一个很好的指南https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions来设置您的本地web开发环境。在第三部分https://getgrav.org/blog/macos-sierra-apache-ssl Andy Miller解释了如何使用自签名证书设置apache:
这是关键命令:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
但有几个步骤你需要遵循,所以检查,祝你好运!,)
为此我使用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。
博士tl;
ssh -R youruniquesubdomain:80:localhost:3000 serveo.net
您的本地环境可以从https://youruniquesubdomain.serveo.net访问
Serveo是最好的
没有注册。 没有安装。 HTTPS。 全球范围内访问。 您可以指定自定义修复子域。 你可以自己托管它,这样你就可以使用自己的域名,即使服务宕机,你也可以为未来做准备。
当我发现这项服务时,我简直不敢相信。它提供了一切,而且是最容易使用的。如果有这样一个简单无痛的工具可以解决所有问题……
这适用于Windows 10和Apache24:
1 -将此添加到C:/Apache24/conf/httpd.conf的底部
Listen 443
<VirtualHost *:443>
DocumentRoot "C:/Apache24/htdocs"
ServerName localhost
SSLEngine on
SSLCertificateFile "C:/Apache24/conf/ssl/server.crt"
SSLCertificateKeyFile "C:/Apache24/conf/ssl/server.key"
</VirtualHost>
2—添加服务器。CRT和服务器。打开“C:/Apache24/conf/ssl”文件夹下的key文件。请参阅本页上的其他答案,以找到这两个文件。
就是这样!
另一个简单的方法是在Ubuntu中使用Python Server。
Generate server.xml with the following command in terminal: openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes Note: Assuming you have openssl installed. Save below code in a file named simple-https-server.py in any directory you want to run the server. import BaseHTTPServer, SimpleHTTPServer import ssl httpd = BaseHTTPServer.HTTPServer(('localhost', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./server.pem', server_side=True) httpd.serve_forever() Run the server from terminal: python simple-https-server.py Visit the page at: https://localhost:4443
额外的笔记:
You can change the port in simple-https-server.py file in line httpd = BaseHTTPServer.HTTPServer(('localhost', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler) You can change localhost to your IP in the same line above: httpd = BaseHTTPServer.HTTPServer(('10.7.1.3', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler) and access the page on any device your network connected. This is very handy in cases like "you have to test HTML5 GeoLocation API in a mobile, and Chrome restricts the API in secure connections only".
要点:https://gist.github.com/dergachev/7028596
http://www.piware.de/2011/01/creating-an-https-server-in-python/
推荐文章
- 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
- 为跨源请求设置cookie