我在CentOS上安装了一个apache服务器。 我正在尝试添加SSL。 我能够创build证书和密钥,然后更新/etc/httpd/conf.d/ssl.conf以进行以下configuration:
/etc/httpd/conf.d/ssl.conf
#Where I put my cert SSLCertificateFile /etc/pki/tls/certs/ca.crt #where I put my key SSLCertificateKeyFile /etc/pki/tls/private/ca.key
然后我更新了/etc/httpd/conf/httpd.conf :
/etc/httpd/conf/httpd.conf中
Listen 443 SSLEngine on SSLCertificateFile /etc/pki/tls/certs/ca.crt SSLCertificateKeyFile /etc/pki/tls/private/ca.key
然后我跑service httpd restart ,我得到的错误:
Stopping httpd: [OK] Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:443 [OK]
我需要做什么来启用SSL?
默认情况下,在CentOS中,Apache / httpd使用的文件位于/etc/httpd/conf.d/ssl.conf 。 这个文件作为Apache的configuration和“httpd.conf”文件读入,其中的任何内容都优先于httpd.conf设置。
该文件(默认情况下)包含一个Listen 443指令。 你不能调用该指令两次(因为它会说已经绑定到该端口),所以导致了冲突。 删除后,它的作品。
如果有人在2017年绊倒这个问题…
不需要编辑httpd.conf因为ssl.conf包含我们需要的所有指令:
# When we also provide SSL we have to listen to the # the HTTPS port in addition. # Listen 443 https
…
# SSL Engine Switch: # Enable/Disable SSL for this virtual host. SSLEngine on
当然,通往证书的途径是:
SSLCertificateFile /etc/pki/tls/certs/<mycert>.crt SSLCertificateKeyFile /etc/pki/tls/private/<mykey>.key
换句话说,在ssl.conf添加信息并重新启动httpd服务就足够了。 当然,这只有在最后一行时才有效:
# Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf
…根据上面的文件httpd.conf取消注释,它是默认安装。
系统信息:
cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.3 (Maipo)