apache服务器开启https

2025-10-21 20:58:30

1、生成https证书,测试使用,正式使用需要购买

生成私钥文件  

sudo openssl genrsa -aes256 -out service.key 1024

然后按提示输入密码,文件生成成功

apache服务器开启https

2、生成证书文件并签署

sudo openssl req -sha256 -new -x509 -days 1826 -key service.key -out service.crt

估计提示输入相关信息

Common Name (e.g. server FQDN or YOUR name) []:这一项必须和你的域名一致

apache服务器开启https

3、配置apache,开启https

打开httpd.conf文件:

移除注释

LoadModule ssl_module libexec/apache2/mod_ssl.so

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

apache服务器开启https

apache服务器开启https

4、修改httpd-vhosts.conf文件

修改DocumentRoot "/Users/xunao/website/upload" 为自己的网站路径

指定证书和密钥文件路径

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

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

apache服务器开启https

apache服务器开启https

5、重启apache

用 sudo apachectl configtest 检测配置文件是否有错误(windows为httpd -t)

sudo apachectl restart   (windows为httpd -k restart)

apache服务器开启https

6、访问网站:

https://域名

如果浏览器提示“您的连接不是私密连接”,则需安装证书的本地计算机

apache服务器开启https

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢