Mac apache 配置 SSL访问

1. apache安装

Mac系统已经自带了apache,省去了安装的过程。

配置文件路径:/private/etc/apache2

网站根路径:/Library/WebServer/Documents/

常用命令:

apachectl start #启动

apachectl stop #停止

apachectl configtest #检查配置

2. 证书生成

#步骤1:生成密钥

openssl genrsa 1024 > server.key

#步骤2: 生成证书请求文件

openssl req -new -key server.key > server.csr

#步骤3: 生成证书

命令:openssl req -x509 -days 365 -key server.key -in server.csr > server.crt

3. 配置SSL

#拷贝证书相关文件到配置路径

cp server.key server.crt /private/etc/apache2/ssl

#修改httpd.conf,以下三行取消注释

LoadModule ssl_module libexec/apache2/mod_ssl.so

Include /private/etc/apache2/extra/httpd-ssl.conf

LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so

#修改httpd-ssl.conf,找到VirtualHost,修改主机名(绿色区域),证书相关文件路径(蓝色区域)

<VirtualHost www.segmentfault.com.gao:443>
#   General setup for the virtual host
DocumentRoot "/Library/WebServer/Documents"
ServerName www.segmentfault.com.gao:443
ServerAdmin [email protected]
ErrorLog "/private/var/log/apache2/error_log"
TransferLog "/private/var/log/apache2/access_log"

SSLCertificateFile "/private/etc/apache2/ssl/server.crt"

SSLCertificateKeyFile "/private/etc/apache2/ssl/server.key"

4. 检验

在浏览器输入https://www.segmentfault.com.gao即可访问。

如果有问题,可以通过apachectl configtest查看配置文件的错误

猜你喜欢

转载自blog.csdn.net/gaogaostone/article/details/86487686