下面设置一个自己的测试页面,看看效果:
[iyunv@test1 conf.d]# cd /var/www/html
[iyunv@test1 html]# ls
[iyunv@test1 html]# echo " this is a web test page !!! " > index.html
echo " this is a web test page ls! " > index.html
[iyunv@test1 html]# ls
index.html
[iyunv@test1 html]# cat index.html this is a web test page ls!
[iyunv@test1 html]#
第三步:创建用户个人站点目录和测试文件
第四步:设置权限
[iyunv@test1 tom]# cd /home
[iyunv@test1 home]# ls -ld tom
drwx------ 3 tom tom 4096 Sep 17 09:33 tom
[iyunv@test1 home]# chmod 711 tom
[iyunv@test1 home]# ls -ld tom
drwx--x--x 3 tom tom 4096 Sep 17 09:33 tom
[iyunv@test1 home]# cd tom
[iyunv@test1 tom]# ls -l public_html/
total 4
-rw-r--r-- 1 root root 31 Sep 17 09:33 index.html
[iyunv@test1 tom]# ls -ld public_html/
drwxr-xr-x 2 root root 4096 Sep 17 09:33 public_html/
[iyunv@test1 tom]# chown -R tom.tom /home/tom/
[iyunv@test1 tom]# ls -ld public_html/
drwxr-xr-x 2 tom tom 4096 Sep 17 09:33 public_html/
[iyunv@test1 tom]#
第五步:重新启动httpd服务
[iyunv@test1 tom]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[iyunv@test1 tom]#
1.创建自己的CA机构
[iyunv@test1 conf.d]# cd /etc/pki/
[iyunv@test1 pki]# ls
CA ca-trust java nssdb rpm-gpg rsyslog tls
[iyunv@test1 pki]#cd tls
[iyunv@test1 tls]# ls
cert.pem certs misc openssl.cnf private
[iyunv@test1 tls]# vim openssl.cnf
修改其中的一个内容:
dir = /etc/pki/CA
//注意:这里面CentOS6.5系统中,自带的版本已经是绝对路径了,在早期的版本中都是相对路径,如果不修改成绝对路径,在你签发证书的时候,如果路径不对会报错
[iyunv@test1 pki]# cd /etc/pki/CA/
[iyunv@test1 CA]# ls
certs crl newcerts private
[iyunv@test1 CA]# touch index.txt
[iyunv@test1 CA]# echo "01" > serial
[iyunv@test1 CA]# ls
certs crl index.txt newcerts private serial
[iyunv@test1 CA]# cd private/
[iyunv@test1 private]# ls
[iyunv@test1 private]# cd ..
[iyunv@test1 CA]# ls
certs crl index.txt newcerts private serial
[iyunv@test1 CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
.............................+++
......................+++
e is 65537 (0x10001)
[iyunv@test1 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
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) []:jiangsu
Locality Name (eg, city) [Default City]:suzhou
Organization Name (eg, company) [Default Company Ltd]:woniu
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:test1.lxm.com
Email Address []:
[iyunv@test1 CA]#
到这里为止,一个简单的CA证书机构就基本构建好了
2.给web站点申请证书
[iyunv@test1 CA]# cd /etc/httpd
[iyunv@test1 httpd]# ls
conf conf.d logs modules run
[iyunv@test1 httpd]# mkdir ssl
[iyunv@test1 httpd]# cd ssl
[iyunv@test1 ssl]# openssl genrsa -out httpd.key 2048
Generating RSA private key, 2048 bit long modulus
............................................................................+++
.......................+++
e is 65537 (0x10001)
[iyunv@test1 ssl]# openssl req -new -key httpd.key -out httpd.csr -days 3650
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) []:jiangsu
Locality Name (eg, city) [Default City]:suzhou
Organization Name (eg, company) [Default Company Ltd]:woniu
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:10.0.10.11 //这里的主机名一定要注意,必须和你的浏览器中访问的主机名一致,我这里图方便就用ip了,那么浏览器中访问的时候就必须用ip来访问
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[iyunv@test1 ssl]# openssl ca -in httpd.csr -out httpd.crt
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Sep 17 03:52:53 2014 GMT
Not After : Sep 17 03:52:53 2015 GMT
Subject:
countryName = CN
stateOrProvinceName = jiangsu
organizationName = woniu
organizationalUnitName = IT
commonName = 10.0.10.11
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
4C:6D:2E:B1:BD:8E:D7:9F:1C:A1:33:CC:32:BD:26:09:1E:0D:C2:48
X509v3 Authority Key Identifier:
keyid:AD:5F:E5:75:D2:B7:EC:51:9D:D9:F8:AB:38:09:98:3E:B0:44:DD:6F
Certificate is to be certified until Sep 17 03:52:53 2015 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[iyunv@test1 ssl]# ls
httpd.crt httpd.csr httpd.key
[iyunv@test1 ssl]#
到这里为止,证书申请就完成了。
3.配置ssl
对于使用rpm安装的httpd来说,还要安全另外一个软件包来提供ssl站点的功能。
[iyunv@test1 ssl]# yum -y install mod_ssl
[iyunv@test1 ssl]# cd /etc/httpd/
[iyunv@test1 httpd]# ls
conf conf.d logs modules run ssl
[iyunv@test1 httpd]# cd conf.d
[iyunv@test1 conf.d]# ls
README ssl.conf welcome.conf
[iyunv@test1 conf.d]#
从上面的信息可见,多出了一个ssl.conf的文件,这个文件就是用来配置ssl站点的
[iyunv@test1 conf.d]# vim ssl.conf
修改下面两句话为你要使用的证书和私钥文件
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key