Apache是当今最为流行的web服务器,apache的站点安全可以通过身份验证、来源控制和加密访问来解决。首先我们安装一下http,至于rpm安装小编就不在这里多说了。下面给大家好好讲解一下httpd.conf这个文件里面的内容。我都给大家很好的注释在了上面,好好了解一下他们,很有助于我们来解决apache的站点安全。



服务器监听端口: Listen 80 监听端口



下面我们来看一下第一种站点安全的解决方法:
1.身份验证
在配置文件中修改 alloworverride all

编辑一下说明文件 .htaccess

authuserfile /var/www/.htpasswd
authname "please input your name and password"
authtype basic
require valid-user

产生帐号文件
htpasswd -c 张号文件 帐号


下面我们来看看访问效果



2.来源控制
在站点主目录中我们可以限制访问的ip地址来达到来源的控制,实现站点安全
Order allow,deny
deny from 192.168.2.100
allow from all
我们要注意的是Order allow,deny 中allow和deny的顺序,他们的顺序决定了是先执行的顺序。




3.加密访问
【原理】
HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,提供了身份验证与加密通讯方法,现在它被广泛用于万维网上安全敏感的通讯,例如交易支付方面。它的主要作用可以分为两种:一种是建立一个信息安全通道,来保证数据传输的安全;另一种就是确认网站的真实性。
【环境】
服务器Linux rhel5.4
客服端windows xp
安装的软件包httpd-2.2.3-31.el5.i386.rpm
mod_ssl-2.2.3-31.el5.i386.rpm
distcache-1.4.5-14.1.i386.rpm
【实验拓扑图】

【实现步骤】
首先检查是否安装openssl



实现摘要:
文件实现方法: openssl md5/sha 文件名
信息实现方法: echo “信息” |openssl md5/sha



公钥私钥对的产生:
私钥的产生:openssl gensa 1024 产生一个1024位长度的私钥
openssl gensa 1024 >key.pem 产生到key.pem文件中去
私钥需要严格保管,需要修改权限:
chmod 600 key.pem
公钥可以在私钥中提取:
openssl rsa -in key.pem -pubout -out public.key
证书的实现步骤:
openssl genrsa 1024 >私钥文件
openssl req -new -key 私钥文件 -out 请求文件
openssl ca -in 请求文件 -out 证书
创建CAlinux CA 【openca】
简易的我们一般使用【openssl】
1.vim /etc/pki/tls/openssl.conf



2.进入/etc/pki/CA创建文件夹和文件
mkdir certs newcerts crl
touch index.txt serial


3.私钥过程:
创建私钥 openssl genrsa 1024 >private/cakey.pem
修改权限Chmod 600 private/*

给自己创建一个证书openssl req -new -key private/cakey.pem -x509 -out cacert.pem

web server
安装模块

查看一下安装生成的文件

创建目录

产生私钥文件openssl genrsa 1024 >私钥文件
产生请求文件openssl req -new -key 私钥文件 -out 请求文件

产生证书: openssl ca -in 请求文件 -out 证书
cd /etc/httpd/certs

捆绑 ssl.conf
Vim /etc/httpd/conf.d/ssl.conf

接下来重启service httpd restart
查看一下端口是否打开

下面我们来看看访问效果

我们可以看到浏览器呈现了证书

因为在客户端上没有证书,所以才会说不是由受信任的公司颁发
Vim /etc/httpd/conf.d/ssl.conf


将证书安装一下,查看一下受信任的证书颁发机构

再次访问一下

发现名称无效或不匹配
我们需要在本机hosts文件中加入
192.168.2.100 www.abc.com
然后在/etc/httpd/conf/httpd.conf中禁用80端口再来访问

本文出自 “木小浩-51CTO” 博客,请务必保留此出处http://muxiaohao.blog.51cto.com/7208070/1282980
(责任编辑:IT) |