配置流程
一般情况下,httpd的安装,默认没有mod_ssl模块,需要通过yum自行安装。
#可以通过httpd -M指令查询是否存在ssl模块#如果httpd.conf文件还没有配置ServerName,则-M操作会报错httpd -M |grep ssl#yum安装mod_sslyum install -y mod_ssl.x86_64systemctl restart httpdhttpd -M|grep ssl#在httpd下创建一个存放ssl证书的cert目录mkdir cert#配置sslvim conf.d/ssl.conf## When we also provide SSL we have to listen to the# standard HTTPS port in addition.#Listen 443 https#### SSL Global Context#### All SSL configuration in this context applies both to## the main server and all SSL-enabled virtual hosts.### Pass Phrase Dialog:# Configure the pass phrase gathering process.# The filtering dialog program (`builtin' is a internal# terminal dialog) has to provide the pass phrase on stdout.SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog# Inter-Process Session Cache:# Configure the SSL Session Cache: First the mechanism# to use and second the expiring timeout (in seconds).SSLSessionCache shmcb:/run/httpd/sslcache(512000)SSLSessionCacheTimeout 300## Use "SSLCryptoDevice" to enable any supported hardware# accelerators. Use "openssl engine -v" to list supported# engine names. NOTE: If you enable an accelerator and the# server does not start, consult the error logs and ensure# your accelerator is functioning properly.#SSLCryptoDevice builtin#SSLCryptoDevice ubsec#### SSL Virtual Host Context##<VirtualHost _default_:443>DocumentRoot "/var/www/html"ServerName www.hunzi.onlineErrorLog logs/ssl_error_logTransferLog logs/ssl_access_logLogLevel warnSSLEngine onSSLHonorCipherOrder onSSLCipherSuite PROFILE=SYSTEMSSLProxyCipherSuite PROFILE=SYSTEM<FilesMatch "\.(cgi|shtml|phtml|php)$">SSLOptions +StdEnvVars</FilesMatch><Directory "/var/www/cgi-bin">SSLOptions +StdEnvVars</Directory>BrowserMatch "MSIE [2-5]" \nokeepalive ssl-unclean-shutdown \downgrade-1.0 force-response-1.0CustomLog logs/ssl_request_log \"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"SSLProtocol all -SSLv2 -SSLv3SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUMSSLHonorCipherOrder onSSLCertificateFile cert/www.hunzi.online_public.crtSSLCertificateKeyFile cert/www.hunzi.online.keySSLCertificateChainFile cert/www.hunzi.online_chain.crt</VirtualHost>#检查配置文件正确性httpd -tsystemctl restart httpd
利用rewrite实现强制用户通过https访问服务
RewriteEngine onRewriteCond %{SERVER_PORT} !^443$RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R]
