- 生成主机密钥
这里会要求输入密码,不输入,直接回车
执行过程:sudo mkdir /private/etc/apache2/ssl cd /private/etc/apache2/ssl sudo ssh-keygen -f server.key
localhost:~ yuanpinghua$ sudo mkdir /private/etc/apache2/ssl Password: localhost:~ yuanpinghua$ cd /private/etc/apache2/ssl localhost:ssl yuanpinghua$ sudo ssh-keygen -f server.key Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in server.key. Your public key has been saved in server.key.pub. The key fingerprint is: SHA256:MX4CY5k2ehZtPjp+SQ3F5Au+RKdYrlpN+ycdI43MlQw root@localhost The key's randomart image is: +---[RSA 2048]----+ | o. | | + .E | | X O.oo . | | + #.* .+ | | . + S=o+ | | o *.** + | | =.+. o o | | + .o.. o | | . .. .o | +----[SHA256]-----+
生成证书请求文件
sudo openssl req -new -key server.key -out request.csr
执行过程:
localhost:ssl yuanpinghua$ sudo openssl req -new -key server.key -out request.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []: Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
生成ssl证书
用上一步生成的文件生成ssl证书sudo openssl x509 -req -days 365 -in request.csr -signkey server.key -out server.crt
到这里,自签名证书就生成好了,下面就开始配置Apache
/private/etc/apache2/httpd.conf
,编辑这个文件去掉下面三行前面的 ‘#’LoadModule ssl_module libexec/apache2/mod_ssl.so Include /private/etc/apache2/extra/httpd-ssl.conf Include/private/etc/apache2/extra/httpd-vhosts.conf
/private/etc/apache2/extra/httpd-ssl.conf
,编辑这个文件去掉下面两行前面的 ‘#’``` SSLCertificateFile "/private/etc/apache2/ssl/server.crt" SSLCertificateKeyFile "/private/etc/apache2/ssl/server.key" ```
/private/etc/apache2/extra/httpd-vhosts.conf
,编辑这个文件在'NameVirtualHost*:80'
后面添加<VirtualHost *:443> SSLEngine on SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL SSLCertificateFile /private/etc/apache2/ssl/server.crt SSLCertificateKeyFile /private/etc/apache2/ssl/server.key ServerName localhost DocumentRoot "/Library/WebServer/Documents" </VirtualHost>
复制凭证和密钥到apache2目录下
将/private/ect/apache2/ssl中的server.crt,server.key 复制到/private/ect/apache2/下到这里就配置完了,检查配置,没问题的话重启Apache就好了
sudo apachectl configtest 检查配置 sudo apachectl -k restart 强制重启
在浏览器中输入:可以正常访问
https://localhost/ , https://192.168.0.1/ ,http://localhost/ , http://192.168.0.106/
上一篇

安装charles
安装sslproxy证书
电脑端(Mac): charles–>help–>SSL Proxying –> install charles Root certificate在密钥管理中将该证书设置
2016-09-03
下一篇

常用操作:
打开终端,运行启动Apache命令:`sudo apachectl start
2. 关闭命令:
sudo apachectl stop
3. 重启命令
sudo apachectl restart
4. 查看Apache版本
2016-09-02