且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 WAMP 服务器 (v2.5) 中启用 https (localhost) url?

更新时间:2023-02-24 15:02:19

您必须先使用密钥和证书设置 WAMP:

You have to set up your WAMP first with key and a certificate:

  1. 此处下载openssl,根据您的操作系统选择合适的版本.
  2. 安装它,然后运行 ​​cmd 并找到安装它的位置:cd 'C:\OpenSSL-Win**' 确保在适当的文件夹中

  1. Download openssl choose the appropriate version according to your Operating system from here.
  2. Install it, than run the cmd and get where you've installed it: cd 'C:\OpenSSL-Win**' be sure be in the appropriate folder

运行这些命令:

  • C:\OpenSSL-Win..\bin>openssl genrsa -aes256 -out private.key 2048
  • C:\OpenSSL-Win..\bin>openssl rsa -in private.key -out private.key
  • C:\OpenSSL-Win..\bin>openssl req -new -x509 -sha1 -key private.key -out certificate.crt -days 36500 -config C:\OpenSSL-Win..\bin\openssl.cfg

系统会要求您输入 private.key国家/地区名称 等的密码.

You will be asked to enter a pass phrase for private.key, Country Name and so on.

完成后,将生成文件:private.keycertificate.crt,创建一个文件夹,将其命名为 key 在这个路径 C:\wamp...bin\apache\apache2.*.**\conf .

Once you are done, the files will be generated: private.key and certificate.crt, create a folder, name it key in this path C:\wamp...bin\apache\apache2.*.**\conf .

打开这个文件httpd.conf.您将在 C:\wamp...bin\apache\apache2.*.**\conf 中找到它,通过删除开头的 # 取消注释这些行行,而不是保存文件.

Open this file httpd.conf. You'll find it in C:\wamp...bin\apache\apache2.*.**\conf uncomment these lines by removing # at the beginning of the line, than save the file.

LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
Include conf/extra/httpd-ssl.conf

  • 打开 httpd-ssl.conf 文件,你也会在 C:\wamp...bin\apache\apache2.*.**\conf\ 中找到它extra 并通过这些行更改默认值,注意路径,我在 C:/wamp../bin/apache/apache2 中创建了一个文件夹 ssl .*.**/logs/

  • Open httpd-ssl.conf file you'll find it also in C:\wamp...bin\apache\apache2.*.**\conf\extra and change the default value by these lines, pay attention to the path, I ve created a folder ssl inside C:/wamp../bin/apache/apache2.*.**/logs/

    <VirtualHost _default_:443>
    #   General setup for the virtual host
    DocumentRoot "C:/wamp../www"
    ServerName localhost:443
    ServerAdmin admin@example.com
    ErrorLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/error.log"
    TransferLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/access.log"
    ....
    CustomLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/ssl_request.log" \
    ....
    SSLCertificateFile "C:/wamp../bin/apache/apache2.*.**/conf/key/certificate.crt"
    SSLCertificateKeyFile "C:/wamp../bin/apache/apache2.*.**/conf/key/private.key"
    

    完成后保存您的文件.

    我复制了 ssleay32.dll &libeay32.dll 从 C:\wamp..\bin\php\php7.0.10 文件夹到 c:\windows\system32.

    I copied ssleay32.dll & libeay32.dll from C:\wamp..\bin\php\php7.0.10 folder to c:\windows\system32.

    最后检查 cd C:\wamp64\bin\apache\apache2.4.23\bin 中的配置并运行此命令 httpd -t 如果一切正常没关系,你会得到的.

    finaly check the configuration get in cd C:\wamp64\bin\apache\apache2.4.23\bin and run this command httpd -t if everything is okay you will get .

    C:\wamp64\bin\apache\apache2.4.23\bin>httpd -t
    Syntax OK
    

  • https://localhost/ 对你有用 :)