web服务器站点安全
2014-01-17 19:28
330 查看
一、身份验证
身份验证主要是对目录的安全性设置.配置web服务器的身份验证:vim /etc/httpd/conf/httpd.conf<Directory "/var/www/html">必须在站点目录里面AllowOverride all //none改为all 该实验服务器上配置文件是在第338行< /Directory >cd /var/www/html //进入站点主目录下创建 .htaccess文件
authuserfile /var/www/.htpasswd authname"please input your name and password"authtype basicrequire valid-user//这里提到了.htpasswd文件,这个文件是要生成的[root@ahao www]#htpasswd -c .htpasswd aaa //创建aaa用户密码123New password: 123//这里只做演示、实验中密码是不显示的Re-type new password:123[root@ahao html]# echo "hello!!" >index.html//在服务器的默认站点上创建一个测试页面//配置这些之后就可以了重启服务器,再次web访问就可以实现身份验证登录了。
![](http://s3.51cto.com/wyfs02/M02/11/B1/wKiom1LZExbBh6GZAAGjqUHqN6o690.jpg)
二、来源控制在服务器的配置文件中有这样的配置:<Directory "/var/www/html">order allow,deny //343行allow from all< /Directory >order allow.deny是表示我们验证这些IP是优先验证允许的还是拒绝的,allow在前就先验证,默认是这样。如果想要控制只能固定IP可以登录就可以这样设置:order deny,allowallow from 192.168.1.111 这样的配置方式就可以实现,这两条语句是顺序实现的,谁在前,谁先执行。
但是需要注意的是:来源控制和身份验证都必须在站点主目录下的配置文件中书写配置,其他地方视作无效。
三、加密访问(https)这里我们要实现一次web服务器的加密访问,实验过程是,服务器上实现数字证书,让主机识别数字证书,传递公钥,进行加密访问。
CA服务器配置以为我们是在centos操作系统上为了简单快捷,我们使用openssl这种方式。
在我们当前系统下,openssl软件包是安装好了。
[root@ahao~]# cd /etc/pki/ //pki,是公钥的基础设施
[root@ahaotls]# vim openssl.cnf
[root@ahao CA]#touch index.txt //配置文件中说明需要这个文件、文件主要存储发行证书的存储。[root@ahao CA]#touch serial //创建自身机构证书的存放文件[root@ahao CA]#echo "01">serial //设定序号[root@ahao CA]#openssl genrsa 1024 >private/cakey.pem //使用openssl生成私钥文件[root@ahao CA]#ll private/cakey.pem rsa:加密算法-rw-r--r--. 1root root 891 Nov 30 06:08 private/cakey.pem[root@ahao CA]#chmod 600 private/cakey.pem //以为这种文件是机密的,所以只能有管理员可以看到,所以更改权限[root@ahao CA]#openssl req -new -key private/cakey.pem -x509 -out cacert.pem//产生公钥文件You are about tobe asked to enter information that will be incorporatedinto yourcertificate request.What you areabout to enter is what is called a Distinguished Name or a DN.There are quitea few fields but you can leave some blankFor some fieldsthere will be a default value,If you enter'.', the field will be left blank.-----Country Name (2letter code) [CN]: //输入国家State orProvince Name (full name) [HENAN]: //输入省份Locality Name(eg, city) [ZH]: //输入城市OrganizationName (eg, company) [Default Company Ltd]:securecenter // 组织名称OrganizationalUnit Name (eg, section) []:tec //部门Common Name (eg,your name or your server's hostname) []:rootca.net.org //公用名Email Address[]: //email 地址
Web服务器配置:[root@ahao CA]#mkdir -pv /etc/httpd/certs //服务器私钥、公钥文件存放位置[root@ahao CA]#cd /etc/httpd/certs/[root@ahaocerts]# openssl genrsa 1024 >httpd.key //创建私钥文件[root@ahaocerts]# chmod 600 httpd.key[root@ahao pki]#vim tls/openssl.cnf [ policy_match ] //设置可以颁发的证书的可选性,不会局限在某一地区或机构 85 countryName = optional 86 stateOrProvinceName = optional 87 organizationName = optional[root@ahaocerts]# openssl req -new -key httpd.key -out httpd.crq //web服务器想CA请求证书的请求文件You are about tobe asked to enter information that will be incorporatedinto yourcertificate request.What you areabout to enter is what is called a Distinguished Name or a DN.There are quitea few fields but you can leave some blankFor some fieldsthere will be a default value,If you enter'.', the field will be left blank.-----Country Name (2letter code) [CN]:State orProvince Name (full name) [HENAN]:Locality Name(eg, city) [ZH]:OrganizationName (eg, company) [Default Company Ltd]:abcOrganizationalUnit Name (eg, section) []:tecCommon Name (eg,your name or your server's hostname) []:www.abc.comEmail Address []:
Please enter thefollowing 'extra' attributesto be sent withyour certificate requestA challengepassword []:An optionalcompany name []:
[root@ahaocerts]# openssl ca -in httpd.crq -outhttpd.cert //CA发放给web服务器的证书
web服务与证书的绑定[root@ahaocerts]# yum --disablerepo=\*--enablerepo=c6-media install mod_ssl [root@ahaocerts]# vim /etc/httpd/conf.d/ssl.conf //编辑ssl配置文件,需要告知web服务器证书与私钥存放的位置。SSLCertificateFile /etc/httpd/certs/httpd.cert //证书存放的目录 105行SSLCertificateKeyFile /etc/pki/httpd/certs/httpd.key //私钥存放的目录 112行SSLCertificateChainFile/etc/pki/CA/cacert.pem //主机也必须要能看到证书所在,所以还要指明CA服务器上,证书在哪里[root@ahaocerts]# service httpd restart //重启服务Stoppinghttpd: [ OK ]Starting httpd: [ OK ]
主机配置:我们现在访问web服务器的话,肯定是不会成功的,以为我们的证书还没有安装到客户机上,并且我们web服务器证书上,指明了我们的Common Name 为www.abc.com,我们直接访问主机的ip是不会直接成功的,所以我们在试验中就将www.abc.com加入本地dns解析文件中。在C:\WINDOWS\system32\drivers\etc\hosts添加一行:192.168.1.199 www.abc.com
![](http://s3.51cto.com/wyfs02/M00/11/B1/wKiom1LZE1LB1ZMiAACxO0asknA672.jpg)
![](http://s3.51cto.com/wyfs02/M02/11/B0/wKioL1LZE0nBx-FxAAE1FtawzQI818.jpg)
本文出自 “eyes,say” 博客,请务必保留此出处http://eyessay.blog.51cto.com/8365949/1352654
身份验证主要是对目录的安全性设置.配置web服务器的身份验证:vim /etc/httpd/conf/httpd.conf<Directory "/var/www/html">必须在站点目录里面AllowOverride all //none改为all 该实验服务器上配置文件是在第338行< /Directory >cd /var/www/html //进入站点主目录下创建 .htaccess文件
authuserfile /var/www/.htpasswd authname"please input your name and password"authtype basicrequire valid-user//这里提到了.htpasswd文件,这个文件是要生成的[root@ahao www]#htpasswd -c .htpasswd aaa //创建aaa用户密码123New password: 123//这里只做演示、实验中密码是不显示的Re-type new password:123[root@ahao html]# echo "hello!!" >index.html//在服务器的默认站点上创建一个测试页面//配置这些之后就可以了重启服务器,再次web访问就可以实现身份验证登录了。
![](http://s3.51cto.com/wyfs02/M02/11/B1/wKiom1LZExbBh6GZAAGjqUHqN6o690.jpg)
二、来源控制在服务器的配置文件中有这样的配置:<Directory "/var/www/html">order allow,deny //343行allow from all< /Directory >order allow.deny是表示我们验证这些IP是优先验证允许的还是拒绝的,allow在前就先验证,默认是这样。如果想要控制只能固定IP可以登录就可以这样设置:order deny,allowallow from 192.168.1.111 这样的配置方式就可以实现,这两条语句是顺序实现的,谁在前,谁先执行。
但是需要注意的是:来源控制和身份验证都必须在站点主目录下的配置文件中书写配置,其他地方视作无效。
三、加密访问(https)这里我们要实现一次web服务器的加密访问,实验过程是,服务器上实现数字证书,让主机识别数字证书,传递公钥,进行加密访问。
CA服务器配置以为我们是在centos操作系统上为了简单快捷,我们使用openssl这种方式。
在我们当前系统下,openssl软件包是安装好了。
[root@ahao~]# cd /etc/pki/ //pki,是公钥的基础设施
[root@ahaotls]# vim openssl.cnf
[root@ahao CA]#touch index.txt //配置文件中说明需要这个文件、文件主要存储发行证书的存储。[root@ahao CA]#touch serial //创建自身机构证书的存放文件[root@ahao CA]#echo "01">serial //设定序号[root@ahao CA]#openssl genrsa 1024 >private/cakey.pem //使用openssl生成私钥文件[root@ahao CA]#ll private/cakey.pem rsa:加密算法-rw-r--r--. 1root root 891 Nov 30 06:08 private/cakey.pem[root@ahao CA]#chmod 600 private/cakey.pem //以为这种文件是机密的,所以只能有管理员可以看到,所以更改权限[root@ahao CA]#openssl req -new -key private/cakey.pem -x509 -out cacert.pem//产生公钥文件You are about tobe asked to enter information that will be incorporatedinto yourcertificate request.What you areabout to enter is what is called a Distinguished Name or a DN.There are quitea few fields but you can leave some blankFor some fieldsthere will be a default value,If you enter'.', the field will be left blank.-----Country Name (2letter code) [CN]: //输入国家State orProvince Name (full name) [HENAN]: //输入省份Locality Name(eg, city) [ZH]: //输入城市OrganizationName (eg, company) [Default Company Ltd]:securecenter // 组织名称OrganizationalUnit Name (eg, section) []:tec //部门Common Name (eg,your name or your server's hostname) []:rootca.net.org //公用名Email Address[]: //email 地址
Web服务器配置:[root@ahao CA]#mkdir -pv /etc/httpd/certs //服务器私钥、公钥文件存放位置[root@ahao CA]#cd /etc/httpd/certs/[root@ahaocerts]# openssl genrsa 1024 >httpd.key //创建私钥文件[root@ahaocerts]# chmod 600 httpd.key[root@ahao pki]#vim tls/openssl.cnf [ policy_match ] //设置可以颁发的证书的可选性,不会局限在某一地区或机构 85 countryName = optional 86 stateOrProvinceName = optional 87 organizationName = optional[root@ahaocerts]# openssl req -new -key httpd.key -out httpd.crq //web服务器想CA请求证书的请求文件You are about tobe asked to enter information that will be incorporatedinto yourcertificate request.What you areabout to enter is what is called a Distinguished Name or a DN.There are quitea few fields but you can leave some blankFor some fieldsthere will be a default value,If you enter'.', the field will be left blank.-----Country Name (2letter code) [CN]:State orProvince Name (full name) [HENAN]:Locality Name(eg, city) [ZH]:OrganizationName (eg, company) [Default Company Ltd]:abcOrganizationalUnit Name (eg, section) []:tecCommon Name (eg,your name or your server's hostname) []:www.abc.comEmail Address []:
Please enter thefollowing 'extra' attributesto be sent withyour certificate requestA challengepassword []:An optionalcompany name []:
[root@ahaocerts]# openssl ca -in httpd.crq -outhttpd.cert //CA发放给web服务器的证书
web服务与证书的绑定[root@ahaocerts]# yum --disablerepo=\*--enablerepo=c6-media install mod_ssl [root@ahaocerts]# vim /etc/httpd/conf.d/ssl.conf //编辑ssl配置文件,需要告知web服务器证书与私钥存放的位置。SSLCertificateFile /etc/httpd/certs/httpd.cert //证书存放的目录 105行SSLCertificateKeyFile /etc/pki/httpd/certs/httpd.key //私钥存放的目录 112行SSLCertificateChainFile/etc/pki/CA/cacert.pem //主机也必须要能看到证书所在,所以还要指明CA服务器上,证书在哪里[root@ahaocerts]# service httpd restart //重启服务Stoppinghttpd: [ OK ]Starting httpd: [ OK ]
主机配置:我们现在访问web服务器的话,肯定是不会成功的,以为我们的证书还没有安装到客户机上,并且我们web服务器证书上,指明了我们的Common Name 为www.abc.com,我们直接访问主机的ip是不会直接成功的,所以我们在试验中就将www.abc.com加入本地dns解析文件中。在C:\WINDOWS\system32\drivers\etc\hosts添加一行:192.168.1.199 www.abc.com
![](http://s3.51cto.com/wyfs02/M00/11/B1/wKiom1LZE1LB1ZMiAACxO0asknA672.jpg)
![](http://s3.51cto.com/wyfs02/M02/11/B0/wKioL1LZE0nBx-FxAAE1FtawzQI818.jpg)
本文出自 “eyes,say” 博客,请务必保留此出处http://eyessay.blog.51cto.com/8365949/1352654
相关文章推荐
- Web服务器的搭建和站点安全的实现
- web服务器的搭建以及站点安全
- WEB站点服务器安全配置
- CA证书服务器(6) 利用CA证书配置安全Web站点
- 建立安全的web服务器站点
- 10个步骤保护IIS Web服务器安全
- 谈谈Web服务器在内网的安全问题
- 10个步骤保护IIS Web服务器安全
- [转]Windows2003基本的web服务器安全设置
- Web 服务器iis安全权限设置
- 保护IIS Web服务器安全的十大步骤
- WEB专用服务器的安全设置技巧
- 在ASP.NET中创建安全的web站点
- centos web+mysql服务器的安全
- RHEL6.3配置Apache服务器(1) 配置默认Web站点
- Python 搭建Web站点之Web服务器网关接口
- WEB服务器应用_服务器安全设置之_本地安全策略设置
- CA数字证书服务的配置、搭建安全的WEB服务器、安全的邮件服务器
- web服务器iis安全设置
- web服务器安全加固策略