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


当前回答

我想在@CodeWarrior的非常好的回答中添加一些东西,这在Chrome上完美地工作,但对于Firefox需要额外的步骤。

由于Firefox不支持默认情况下Windows提供的CA证书,您需要继续:config,向下滚动到security.enterprise_root。Enabled并将其更改为true。

现在,您的证书在Firefox上也应该是有效的。

当然,这仅用于开发目的,因为ssl信任是一个关键的安全问题,只有在知道其影响时才更改此设置。

其他回答

这实际上很简单,假设您手边有一个openssl安装。(您在哪个站台?)

假设你使用的是linux/solaris/mac os/x, Van的Apache SSL/TLS mini-HOWTO有一个很好的演练,我在这里就不再赘述了。

但是,执行摘要是您必须创建一个自签名证书。由于您运行apache for localhost大概是为了开发(即不是公共web服务器),您将知道您可以信任自签名证书,并且可以忽略浏览器抛出的警告。

这应该是工作Ubuntu,薄荷类似于Apache2

这是一个很好的指南,所以遵循这个

https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-14-04

然后像这样留下ssl。conf

<VirtualHost _default_:443>
        ServerAdmin your@email.com
        ServerName localhost
        ServerAlias www.localhost.com

        DocumentRoot /var/www


    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

你可以得到它。

希望这对linuxer有帮助

这适用于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文件。请参阅本页上的其他答案,以找到这两个文件。

就是这样!

对于那些使用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

但有几个步骤你需要遵循,所以检查,祝你好运!,)

另一个简单的方法是在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/