将 SSL 添加到 Apache 服务器
Adding SSL to Apache Server
我们今天获得了 SSL 证书,我正在尝试将 SSL 证书添加到域中,以便我们可以通过 https 访问该网站,但是我 运行 遇到了问题。
我们在 windows 上有一个 Apache 服务器 运行。
该配置适用于端口 80,但是当我将端口 443 添加到配置时,一切都停止工作。
启动apache时出现的错误是
The requested operation has failed.
我添加了以下行
Listen 443
下一行:
Listen 80
我添加了以下 VirtualHost 配置
<VirtualHost _default_:443>
DocumentRoot "c:/path/to/website"
ServerName example.com
ServerAlias example.com www.example.com
SSLEngine on
SSLCertificateFile "c:/path/to/cert/cert.crt"
SSLCertificateKeyFile "c:/path/to/cert/key.key"
SSLCACertificateFile "c:/path/to/cert/bundle.ca-bundle"
</VirtualHost>
然而,每当我在添加此后启动 apache 服务器时,它都不会启动,并且出现错误。
我注释掉了一些代码并将问题缩小到 Listen 443
行。添加此内容时有什么我没有考虑到的吗?
这些是 error.log
中的最后 3 行
[Thu Jun 08 18:15:31.909142 2017] [mpm_winnt:notice] [pid 66428:tid 712] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Thu Jun 08 18:15:47.209776 2017] [mpm_winnt:notice] [pid 67332:tid 620] AH00364: Child: All worker threads have exited.
[Thu Jun 08 18:15:48.067933 2017] [mpm_winnt:notice] [pid 66428:tid 712] AH00430: Parent: Child process exited successfully.
编辑
这是来自 运行 httpd.exe -e debug
的回复
(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : AH00072: make_sock: could not bind to address [::]:443
(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : AH00072: make_sock: could not bind to address 0.0.0.0:443
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs
我不知道你的 httpd.conf 文件是什么样子的,也许你 deleted/changed 不小心有些值。
您需要做的第一件事是恢复您的 httpd.conf 文件并在没有 SSL 配置的情况下启动服务。一旦成功,您可以继续执行以下步骤:
在一个新文件中将所有 SSL 设置分开,也许一个名为 httpd-ssl.conf 的新文件是个好名字。
之后,在主 httpd.conf 的末尾添加以下行以包含新文件:
# Secure (SSL/TLS) connections
Include conf/httpd-ssl.conf
这是一种很好的做法,可以避免 changing/deleting 在主配置中意外出现某些内容并限制可能的错误来源,您会知道任何错误都与包含的新文件有关。
您的新 conf/httpd-ssl.conf 应如下所示(标准设置):
# HTTPS port
Listen 443
<VirtualHost _default_:443>
# General setup for the virtual host
DocumentRoot "C:/your_httpd_path/htdocs"
ServerName www.example.com:443
ServerAdmin admin@example.com
ErrorLog "C:/your_httpd_path/logs/error.log"
TransferLog "C:/your_httpd_path/logs/access.log"
# SSL Engine Switch:
SSLEngine on
# Server Certificates:
SSLCertificateFile "c:/path/to/cert/cert.crt"
SSLCertificateKeyFile "c:/path/to/cert/key.key"
SSLCACertificateFile "c:/path/to/cert/bundle.ca-bundle"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/your_httpd_path/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
CustomLog "C:/your_httpd_path/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
您是否尝试过使用 httpd.exe -e debug?也许我们可以在这种模式下找到有用的东西。
更新:啊哈!你有错误!它可能是 443 某处的重复行。
你能在记事本++中检查你的文件并搜索所有匹配“443”的巧合吗?可能您已经配置了 443 并尝试再次添加它?你只需要一行:
Listen 443
或者可能已经 运行 在那个港口?检查:
netstat -na | findstr "443"
如果你有类似的东西:
TCP [::]:443 [::]:0 LISTENING
然后您的 443 端口上有其他东西 运行。无论如何,您可以更改您的 httpd conf 并设置任何其他端口,如 4443,即或终止正在占用 443 的进程。
我们今天获得了 SSL 证书,我正在尝试将 SSL 证书添加到域中,以便我们可以通过 https 访问该网站,但是我 运行 遇到了问题。
我们在 windows 上有一个 Apache 服务器 运行。
该配置适用于端口 80,但是当我将端口 443 添加到配置时,一切都停止工作。
启动apache时出现的错误是
The requested operation has failed.
我添加了以下行
Listen 443
下一行:
Listen 80
我添加了以下 VirtualHost 配置
<VirtualHost _default_:443>
DocumentRoot "c:/path/to/website"
ServerName example.com
ServerAlias example.com www.example.com
SSLEngine on
SSLCertificateFile "c:/path/to/cert/cert.crt"
SSLCertificateKeyFile "c:/path/to/cert/key.key"
SSLCACertificateFile "c:/path/to/cert/bundle.ca-bundle"
</VirtualHost>
然而,每当我在添加此后启动 apache 服务器时,它都不会启动,并且出现错误。
我注释掉了一些代码并将问题缩小到 Listen 443
行。添加此内容时有什么我没有考虑到的吗?
这些是 error.log
中的最后 3 行[Thu Jun 08 18:15:31.909142 2017] [mpm_winnt:notice] [pid 66428:tid 712] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Thu Jun 08 18:15:47.209776 2017] [mpm_winnt:notice] [pid 67332:tid 620] AH00364: Child: All worker threads have exited.
[Thu Jun 08 18:15:48.067933 2017] [mpm_winnt:notice] [pid 66428:tid 712] AH00430: Parent: Child process exited successfully.
编辑
这是来自 运行 httpd.exe -e debug
(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : AH00072: make_sock: could not bind to address [::]:443
(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : AH00072: make_sock: could not bind to address 0.0.0.0:443
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs
我不知道你的 httpd.conf 文件是什么样子的,也许你 deleted/changed 不小心有些值。
您需要做的第一件事是恢复您的 httpd.conf 文件并在没有 SSL 配置的情况下启动服务。一旦成功,您可以继续执行以下步骤:
在一个新文件中将所有 SSL 设置分开,也许一个名为 httpd-ssl.conf 的新文件是个好名字。
之后,在主 httpd.conf 的末尾添加以下行以包含新文件:
# Secure (SSL/TLS) connections
Include conf/httpd-ssl.conf
这是一种很好的做法,可以避免 changing/deleting 在主配置中意外出现某些内容并限制可能的错误来源,您会知道任何错误都与包含的新文件有关。
您的新 conf/httpd-ssl.conf 应如下所示(标准设置):
# HTTPS port
Listen 443
<VirtualHost _default_:443>
# General setup for the virtual host
DocumentRoot "C:/your_httpd_path/htdocs"
ServerName www.example.com:443
ServerAdmin admin@example.com
ErrorLog "C:/your_httpd_path/logs/error.log"
TransferLog "C:/your_httpd_path/logs/access.log"
# SSL Engine Switch:
SSLEngine on
# Server Certificates:
SSLCertificateFile "c:/path/to/cert/cert.crt"
SSLCertificateKeyFile "c:/path/to/cert/key.key"
SSLCACertificateFile "c:/path/to/cert/bundle.ca-bundle"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/your_httpd_path/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
CustomLog "C:/your_httpd_path/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
您是否尝试过使用 httpd.exe -e debug?也许我们可以在这种模式下找到有用的东西。
更新:啊哈!你有错误!它可能是 443 某处的重复行。
你能在记事本++中检查你的文件并搜索所有匹配“443”的巧合吗?可能您已经配置了 443 并尝试再次添加它?你只需要一行:
Listen 443
或者可能已经 运行 在那个港口?检查:
netstat -na | findstr "443"
如果你有类似的东西:
TCP [::]:443 [::]:0 LISTENING
然后您的 443 端口上有其他东西 运行。无论如何,您可以更改您的 httpd conf 并设置任何其他端口,如 4443,即或终止正在占用 443 的进程。