随着LAMP环境的成熟应用,apache站点的安全性也被提出来了,有时候因为意外的各种原因,会导致站点内的某些信息泄漏,照成不必要的麻烦。所以Apache的安全被提出来,并做了安全提升,apache的安全可以从下面几个方面入手:
实验环境:
Red Hat Enterprise Linux 5.4 32-bit
httpd-2.4.4.tar.bz2
mysql-5.6.10.tar-gz
php-5.4.14.tar.gz
第一部分:身份验证
[root@bogon ~]# vim /etc/httpd/conf/httpd.conf


进行身份验证

在站点的主目录下面
说明文件.htaccess

htpasswd -c .htaccess 用户名
#第一次使用时,使用上面的命令说明,否则不用加参数-c

第二部分:来源控制
基于ip地址的访问
可以拒绝某些IP地址的访问
下面演示的是拒绝ip地址是192.168.30.200的主机访问192.168.30.100
[root@bogon ~]# vim /etc/httpd/conf/httpd.conf
#拒绝来源IP为192.168.30.200的机器
第三部分:https
https是由Netscape开发并内置于其浏览器中,用于对数据进行压缩和解压操作,并返回网络上传送回的结果。HTTPS实际上应用了Netscape的安全套接层(SSL)作为HTTP应用层的子层。(HTTPS使用端口443,而不是像HTTP那样使用端口80来和TCP/IP进行通信。)SSL使用40 位关键字作为RC4流加密算法,这对于商业信息的加密是合适的。HTTPS和SSL支持使用X.509数字认证,如果需要的话用户可以确认发送者是谁。
也就是说它的主要作用可以分为两种:一种是建立一个信息安全通道,来保证数据传输的安全;另一种就是确认网站的真实性。
HTTPS和HTTP的区别
一、https协议需要到ca申请证书,一般免费证书很少,需要交费。
二、http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议。
三、http和https使用的是完全不同的连接方式,用的端口也不一样,前者是80,后者是443。
四、http的连接很简单,是无状态的;HTTPS协议是由SSL+HTTP协议构建的可进行加密传输、身份认证的网络协议,比http协议安全。



建立根CA机构需要的3个目录和两个文件
cd /etc/pki/CA
mkdir certs crl newcerts
touch serial index.txt
echo “01”> serial //给serial文件一个初始化序列号01
生成根CA的私钥文件,并修改权限,由私钥文件生成证书文件

Step2:生成Apache服务的私钥文件、有私钥文件生成证书请求文件
mkdir -pv /etc/httpd/certs/
cd /etc/httpd/certs/


Step3:向根CA提交证书请求文件生成证书文件


Step4:对Apache配置修改,结合SSL
修改结合SSL的主配置文件,添加证书的相关路径信息
vim /etc/httpd/extra/httpd-ssl.conf


vim /etc/httpd/httpd.conf


Https访问站点,证书安装过程






安装过证书后的Https访问站点


END ! ! !
(责任编辑:IT) |