冰之巅 發表於 2024-3-8 00:00:00

Centos6.3下Apache配置基于加密的认证https加密证书访问

<p>&nbsp; &nbsp;
        这里简单演示一下Apache下基于加密的认证访问----https加密方式访问。</p><p><strong>1.DNS解析解析情况:</strong></p><p>&nbsp; &nbsp;
        # nslookup www.jb51.net</p><p>&nbsp; &nbsp;
        Server: &nbsp; &nbsp; &nbsp; &nbsp; 192.168.2.115</p><p>&nbsp; &nbsp;
        Address: &nbsp; &nbsp; &nbsp; &nbsp;192.168.2.115#53</p><p>&nbsp; &nbsp;
        Name: &nbsp; www.jb51.net</p><p>&nbsp; &nbsp;
        Address: 192.168.2.115</p><p><strong>2.安装Apache SSL支持模块:# yum install -y mod_ssl (默认yum安装httpd是没有安装该模块的,安装后自动生产/etc/httpd/conf.d/ssl.conf文件)并生成证书。</strong></p><p>&nbsp; &nbsp;
        # pwd</p><p>&nbsp; &nbsp;
        /etc/pki/tls/certs</p><p>&nbsp; &nbsp;
        # ls</p><p>&nbsp; &nbsp;
        ca-bundle.crt &nbsp; &nbsp; &nbsp; &nbsp;index.html &nbsp; &nbsp; &nbsp;localhost.crt &nbsp; &nbsp;Makefile</p><p>&nbsp; &nbsp;
        ca-bundle.trust.crt &nbsp;localhost1.crt &nbsp;make-dummy-cert</p><p>&nbsp; &nbsp;
        # openssl req -utf8 -new -key ../private/localhost.key -x509 -days 3650 -out&nbsp;abc_com.crt</p><p>&nbsp; &nbsp;
        You are about to be asked to enter information that will be incorporated</p><p>&nbsp; &nbsp;
        into your certificate request.</p><p>&nbsp; &nbsp;
        What you are about to enter is what is called a Distinguished Name or a DN.</p><p>&nbsp; &nbsp;
        There are quite a few fields but you can leave some blank</p><p>&nbsp; &nbsp;
        For some fields there will be a default value,</p><p>&nbsp; &nbsp;
        If you enter &#39;.&#39;, the field will be left blank.</p><p>&nbsp; &nbsp;
        -----</p><p>&nbsp; &nbsp;
        Country Name (2 letter code) :CN</p><p>&nbsp; &nbsp;
        State or Province Name (full name) []:510510</p><p>&nbsp; &nbsp;
        Locality Name (eg, city) :GZ</p><p>&nbsp; &nbsp;
        Organization Name (eg, company) :ABC.COM</p><p>&nbsp; &nbsp;
        Organizational Unit Name (eg, section) []:Mr.Zhang</p><p>&nbsp; &nbsp;
        Common Name (eg, your name or your server&#39;s hostname) []:www.jb51.net</p><p>&nbsp; &nbsp;
        Email Address []:root@abc.com</p><p>&nbsp; &nbsp;
        #</p><p><strong>3.配置Apache,基本配置这里不多说了,下面是配置www.jb51.net站点http访问的情况。</strong></p><p>&nbsp; &nbsp;
        # tail -n 8 /etc/httpd/conf/httpd.conf</p><p>&nbsp; &nbsp;
        NameVirtualhost 192.168.2.115:80</p><p><virtualhost www.jb51.net:80=""></virtualhost></p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; ServerAdmin webmaster@dummy-host.example.com</p><p>&nbsp; &nbsp;
        &nbsp; &nbsp;&nbsp;DocumentRoot /var/www/html</p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; ServerName www.jb51.net</p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; ErrorLog logs/dummy-host.example.com-error_log</p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; CustomLog logs/dummy-host.example.com-access_log common</p><p><br/></p><p>&nbsp; &nbsp;
        #&nbsp;tail /var/www/html/index.html</p><p>&nbsp; &nbsp;
        www.jb51.net</p><p>&nbsp; &nbsp;
        #</p><p><strong>4.配置Apache支持https访问www.jb51.net站点,编辑&nbsp;vim /etc/httpd/conf.d/ssl.conf&nbsp;文件,制定www.jb51.net站点https访问时的相关信息。添加下面配置。</strong></p><p><virtualhost www.jb51.net:443=""></virtualhost></p><p>&nbsp; &nbsp;
        DocumentRoot &quot;/var/www/html/www.jb51.net&quot; &nbsp; &nbsp;#//为了显示效果,这里的站点目录不一样,一般情况一个域名应该指向同一目录的。</p><p>&nbsp; &nbsp;
        ServerName www.jb51.net:443</p><p>&nbsp; &nbsp;
        ErrorLog logs/ssl_error_log</p><p>&nbsp; &nbsp;
        TransferLog logs/ssl_access_log</p><p>&nbsp; &nbsp;
        LogLevel warn</p><p>&nbsp; &nbsp;
        SSLEngine on</p><p>&nbsp; &nbsp;
        SSLProtocol all -SSLv2</p><p>&nbsp; &nbsp;
        SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW</p><p>&nbsp; &nbsp;
        SSLCertificateFile /etc/pki/tls/certs/abc_com.crt</p><p>&nbsp; &nbsp;
        SSLCertificateKeyFile /etc/pki/tls/private/localhost.key</p><p><files></files></p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; SSLOptions +StdEnvVars</p><p><br/></p><p><directory></directory></p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; SSLOptions +StdEnvVars</p><p><br/></p><p>&nbsp; &nbsp;
        SetEnvIf User-Agent &quot;.*MSIE.*&quot; \</p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nokeepalive ssl-unclean-shutdown \</p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;downgrade-1.0 force-response-1.0</p><p>&nbsp; &nbsp;
        CustomLog logs/ssl_request_log \</p><p>&nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \&quot;%r\&quot; %b&quot;</p><p><br/></p><p><strong>5.重启Apache服务,测试访问。</strong></p><p><img style="max-width:100%!important;height:auto!important;" src="https://zhuji.jb51.net/uploads/img/20230519/2ac29a7423d680aa663c42736aaf7823.jpg"/></p><p>&nbsp; &nbsp;
        测试http访问的结果</p><p><img style="max-width:100%!important;height:auto!important;" src="https://zhuji.jb51.net/uploads/img/20230519/5f811a53767c90e219b4ef4f530a6d8f.jpg"/></p><p>&nbsp; &nbsp;
        测试https访问的结果</p><p><img style="max-width:100%!important;height:auto!important;" src="https://zhuji.jb51.net/uploads/img/20230519/4b94ca5da35ab55170cc0bdeffda43fc.jpg"/></p><p>&nbsp; &nbsp;
        查看证书信息和自建crt信息一致</p><p><img style="max-width:100%!important;height:auto!important;" src="https://zhuji.jb51.net/uploads/img/20230519/64b8c506d918689db5ef1357cfef8005.jpg"/></p><p>&nbsp; &nbsp;
        https访问的最终结果</p>
頁: [1]
查看完整版本: Centos6.3下Apache配置基于加密的认证https加密证书访问