萬盛學電腦網

 萬盛學電腦網 >> 服務器教程 >> Apache配置基於加密的認證https加密證書訪問

Apache配置基於加密的認證https加密證書訪問

 這裡簡單演示一下Apache下基於加密的認證訪問----https加密方式訪問。

1.DNS解析解析情況:

[root@localhost html]# nslookup www.downcc.com

Server:         192.168.2.115

Address:        192.168.2.115#53

Name:   www.downcc.com

Address: 192.168.2.115

2.安裝Apache SSL支持模塊:# yum install -y mod_ssl (默認yum安裝httpd是沒有安裝該模塊的,安裝後自動生產/etc/httpd/conf.d/ssl.conf文件)並生成證書。

[root@localhost certs]# pwd

/etc/pki/tls/certs

[root@localhost certs]# ls

ca-bundle.crt        index.html      localhost.crt    Makefile

ca-bundle.trust.crt  localhost1.crt  make-dummy-cert

[root@localhost certs]# openssl req -utf8 -new -key ../private/localhost.key -x509 -days 3650 -out abc_com.crt

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:510510

Locality Name (eg, city) [Default City]:GZ

Organization Name (eg, company) [Default Company Ltd]:ABC.COM

Organizational Unit Name (eg, section) []:Mr.Zhang

Common Name (eg, your name or your server's hostname) []:www.downcc.com

Email Address []:[email protected]

[root@localhost certs]#

3.配置Apache,基本配置這裡不多說了,下面是配置www.downcc.com站點http訪問的情況。

[root@localhost html]# tail -n 8 /etc/httpd/conf/httpd.conf

NameVirtualhost 192.168.2.115:80

<VirtualHost www.downcc.com:80>

    ServerAdmin [email protected]

    DocumentRoot /var/www/html

    ServerName www.downcc.com

    ErrorLog logs/dummy-host.example.com-error_log

    CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>

[root@localhost html]# tail /var/www/html/index.html                      

www.downcc.com

[root@localhost html]#

4.配置Apache支持https訪問www.downcc.com站點,編輯 vim /etc/httpd/conf.d/ssl.conf 文件,制定www.downcc.com站點https訪問時的相關信息。添加下面配置。

<VirtualHost www.downcc.com:443>

DocumentRoot "/var/www/html/www.kuteatest.net"    #//為了顯示效果,這裡的站點目錄不一樣,一般情況一個域名應該指向同一目錄的。

ServerName www.downcc.com:443

ErrorLog logs/ssl_error_log

TransferLog logs/ssl_access_log

LogLevel warn

SSLEngine on

SSLProtocol all -SSLv2

SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW

SSLCertificateFile /etc/pki/tls/certs/abc_com.crt

SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

<Files ~ ".(cgi|shtml|phtml|php3?)$">

    SSLOptions +StdEnvVars

</Files>

<Directory "/var/www/cgi-bin">

    SSLOptions +StdEnvVars

</Directory>

SetEnvIf User-Agent ".*MSIE.*"

         nokeepalive ssl-unclean-shutdown

         downgrade-1.0 force-response-1.0

CustomLog logs/ssl_request_log

          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"

</VirtualHost>

5.重啟Apache服務,測試訪問。

Apache配置基於加密的認證https加密證書訪問 三聯

測試http訪問的結果

測試https訪問的結果

查看證書信息和自建crt信息一致

https訪問的最終結果

copyright © 萬盛學電腦網 all rights reserved