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


当前回答

这是最简单的方法

首先复制这些服务器。CRT &服务器。关键文件(见附件)到apache/conf/ssl目录

然后打开httpd.conf文件并添加以下行

Listen 80
Listen 443

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:443>
    DocumentRoot "d:/wamp/www"  #your wamp www root dir
    ServerName localhost
    SSLEngine on
    SSLCertificateFile "d:/wamp/bin/apache/Apache2.4.4/conf/ssl/server.crt"
    SSLCertificateKeyFile "d:/wamp/bin/apache/Apache2.4.4/conf/ssl/server.key"
</VirtualHost>

其他回答

Windows + Apache 2.4,例如:

uncomment ssl_module in your httpd.conf file. LoadModule ssl_module modules/mod_ssl.so listen 443 port just like 80 port in your httpd.conf file. Listen 80 Listen 443 uncomment Include Virtual hosts in your httpd.conf file. # Virtual hosts Include conf/extra/httpd-vhosts.conf add VirtualHost in your conf/extra/httpd-vhosts.conf <VirtualHost _default_:443> DocumentRoot "D:/www" #your site directory path ServerName localhost #ServerAlias localhost.com localhost2.com SSLEngine on SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt" SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key" <Directory "D:/www"> Options -Indexes +FollowSymLinks +ExecCGI AllowOverride All Require all granted </Directory> </VirtualHost>

只有端口号443和SSL......行与正常的HTTP配置不同。

保存配置文件并重新启动apache服务。然后你可以访问https://localhost/

浏览器会在第一时间警告你这是不安全的,选择继续。

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

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

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

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

这是最简单的方法

首先复制这些服务器。CRT &服务器。关键文件(见附件)到apache/conf/ssl目录

然后打开httpd.conf文件并添加以下行

Listen 80
Listen 443

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:443>
    DocumentRoot "d:/wamp/www"  #your wamp www root dir
    ServerName localhost
    SSLEngine on
    SSLCertificateFile "d:/wamp/bin/apache/Apache2.4.4/conf/ssl/server.crt"
    SSLCertificateKeyFile "d:/wamp/bin/apache/Apache2.4.4/conf/ssl/server.key"
</VirtualHost>

为了保护发送到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端点,现在单击高级—>添加例外—>确认安全例外,您将再次看到默认页面。