mon*_*onu 10 rhel configuration ssl apache-httpd
我已经在 RHEL 6 中安装了 apache。一切正常。使用https://localhost:443/应该做的所有更改和配置 。
如果我将“Listen 80”更改为 443,则会引发 SSL 连接错误
“错误 107(net::ERR_SSL_PROTOCOL_ERROR):SSL 协议错误。”
pra*_*tri 13
如果您正在使用apache2
,那么您必须执行以下操作:
步骤 1:使用 OpenSSL 生成用于保护站点的密钥。这些密钥用于加密和解密安全站点的流量。
$ openssl genrsa -out mydomain.key 1024
Run Code Online (Sandbox Code Playgroud)
此命令将创建一个 1024 位私钥并将其放入文件 mydomain.key 中。
第 2 步:生成您自己的证书。
$ openssl req -new -key mydomain.key -x509 -out mydomain.crt
Run Code Online (Sandbox Code Playgroud)
第三步:将私钥保存在目录中/etc/apache2/ssl.key/
,证书保存在目录中/etc/apache2/ssl.crt/
。
注意:该ssl.key
目录必须只能由 root 用户读取。
第4步:现在你需要编辑httpd.conf
文件/etc/apache2
。
现在这个文件应该包含这样的内容:
NameVirtualHost *:80
NameVirtualHost *:443
Listen 443
<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot /srv/www/htdocs/mydomain
ServerName www.mydomain.com
ServerAlias mydomain.com
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@mydomain.com
DocumentRoot /srv/www/htdocs/mydomain-secure
ServerName mail.mydomain.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl.crt/mydomain.crt
SSLCertificateKeyFile /etc/apache2/ssl.key/mydomain.key
</VirtualHost>
<Directory /srv/www/htdocs/mydomain-secure>
SSLRequireSSL
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot /srv/www/htdocs/mydomain
ServerName mail.mydomain.com
RedirectMatch permanent (/.*) https://mail.mydomain.com$1
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
不要更改Listen 80
为443
in /etc/httpd/conf/httpd.conf
. SSL 在 中配置/etc/httpd/conf.d/ssl.conf
。在 RHEL 6 上,SSL 已启用并默认使用自签名证书进行侦听。
您只需浏览即可使用 SSL 访问默认站点https://localhost
(无需将端口添加到 URL 末尾)。
如果您想将所有 HTTP 请求转发到 HTTPS(我相信您正在尝试实现这一目标),您可以添加永久重定向,或者使用 Apache 模块mod_rewrite
。
最简单、最安全的方法是设置永久重定向。启用命名虚拟主机Redirect
并向 中的 VirtualHost 添加指令/etc/httpd/conf/httpd.conf
。
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
Redirect permanent / https://localhost
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
使用mod_rewrite
,您还可以创建一个命名虚拟主机。这不是推荐的方法,但会起作用。
NameVirtualHost *:80
<VirtualHost *:80>
# Enable the Rewrite engine
RewriteEngine On
# Make sure the connection is not already HTTPS
RewriteCond %{HTTPS} !=on
# This rewrites the URL and forwards to https
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
如果您想关闭 SSL,请注释掉这些行/etc/httpd/conf.d/ssl.conf
并重新启动 Apache。
LoadModule ssl_module modules/mod_ssl.so
Listen 443
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
67111 次 |
最近记录: |