DocumentRoot "/usr/local/apache/htdocs/example2.com"
ServerName example2.com
ServerAlias subdomain.example2.com
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "/usr/local/apache/conf/server2.crt"
SSLCertificateKeyFile "/usr/local/apache/conf/server2.key"
SSLCertificateChainFile "/usr/local/apache/conf/1_root_bundle2.crt"
SSLOptions +StdEnvVars
AllowOverride All
SSLOptions +StdEnvVars
修改.htaccess文件实现301永久重定向的例子:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
补充:日志问题,为了简化可以把httpd-ssl.conf中的日志都关闭:
#ErrorLog "/usr/local/apache/logs/error_log"
#TransferLog "/usr/local/apache/logs/access_log"
#CustomLog "/usr/local/apache/logs/ssl_request_log" \ # "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
然后修改httpd.conf中的设置,添加port:%p,从端口号是80还是443来分辨http和https:
LogFormat "%h %l %u %t port:%p \"%{Host}i\" \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/access_%Y-%m-%d.log 86400 480" combined
重启httpd服务后生效,日志文件依然是以前的。
再补充:在部分阿里云国内服务器上使用get_headers('https://www.baidu.com/',1 (link is external));这样的语句报错:
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 在 eval() (行 6 在 /mnt/gb/www/drupal.chahaoba.com/modules/php/php.module(80) : eval()'d code).
Warning: get_headers(): Failed to enable crypto 在 eval() (行 6 在 /mnt/gb/www/drupal.chahaoba.com/modules/php/php.module(80) : eval()'d code).
Warning: get_headers(https://www.baidu.com/node/4): failed to open stream: operation failed 在 eval() (行 6 在 /mnt/gb/www/drupal.chahaoba.com/modules/php/php.module(80) : eval()'d code).
用print_r(openssl_get_cert_locations());打印出来是这样的:
(
[default_cert_file] => /usr/local/ssl/cert.pem
[default_cert_file_env] => SSL_CERT_FILE
[default_cert_dir] => /usr/local/ssl/certs
[default_cert_dir_env] => SSL_CERT_DIR
[default_private_dir] => /usr/local/ssl/private
[default_default_cert_area] => /usr/local/ssl
[ini_cafile] =>
[ini_capath] =>
)
而不报错的国外服务器上打印出来是这样的:
(
[default_cert_file] => /etc/pki/tls/cert.pem
[default_cert_file_env] => SSL_CERT_FILE
[default_cert_dir] => /etc/pki/tls/certs
[default_cert_dir_env] => SSL_CERT_DIR
[default_private_dir] => /etc/pki/tls/private
[default_default_cert_area] => /etc/pki/tls
[ini_cafile] =>
[ini_capath] =>
)
原因可能是安装的Centos版本及php版本上有小的差别,修改/alidata/server/php5/etc/php.ini强制设置证书路径:
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
;curl.cainfo =
[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the> ; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
;openssl.cafile=
openssl.cafile="/etc/pki/tls/cert.pem"
; If openssl.cafile is not specified or if the CA file is not found, the
; directory pointed to by openssl.capath is searched for a suitable
; certificate. This value must be a correctly hashed certificate directory.
; Most users should not specify a value for this directive as PHP will
; attempt to use the OS-managed cert stores in its absence. If specified,
; this value may still be overridden on a per-stream basis via the "capath"
; SSL stream context option.
;openssl.capath=
openssl.capath="/etc/pki/tls/certs"
重启apache后解决。Drupal网站状态报告中的“HTTP 请求状态 失败”也一并解决。
参考链接地址:
https://jamesqi.com/%E5%8D%9A%E5%AE%A2/https%E5%A4%9A%E7%BD%91%E7%AB%991%E4%B8%AAIP%E5%A4%9A%E4%B8%AASSL%E8%AF%81%E4%B9%A6%E7%9A%84Apache%E8%AE%BE%E7%BD%AE%E5%8A%9E%E6%B3%95