您的位置:首页 > 其它

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访问就可以实现身份验证登录了。



二、来源控制在服务器的配置文件中有这样的配置:<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






本文出自 “eyes,say” 博客,请务必保留此出处http://eyessay.blog.51cto.com/8365949/1352654
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: