一、httpd 基于FQDN的虚拟主机配置
以下小字体为配置文件内容,绿色加粗字体为可行的命令
1、安装httpd
yum -y install httpd
2、创建虚拟主机配置文件
vim /etc/httpd/conf.d/www.conf
<VirtualHost172.16.19.11:80>
ServerName www1.abc.com
DocumentRoot /var/www/www1
ErrorLog logs/www1.error_log
CustomLog logs/www1.acess_log common
</VirtualHost>
<VirtualHost172.16.19.11:80>
ServerName www2.abc.com
DocumentRoot /var/www/www2
ErrorLog logs/www2.error_log
CustomLog logs/www2.access_log common
</VirtualHost>
3、打开NameVirtualHost
vim/etc/httpd/conf/httpd.conf
NameVirtualHost172.16.19.11:80
4、创建虚拟主机跟目录
mkdir/var/www/www1; mkdir /var/www/www1;
5、配置文件语法检查
httpd -t
6、启动服务
service httpdrestart
7、创建测试页面
echo "<h1> www1 </h1>"> /var/www/www1/index.html
echo "<h1> www1</h2>" > /var/www/www2/index.html
8、修改本地hosts测试虚拟主机
a) vim /etc/hosts #新建一行添加ip与域名
172.16.19.11 www1.abc.com www2.abc.com
b)测试基于域名的虚拟主机是否工作正常,效果如下图所示
二、为www1.abc.com添加status页面,并设置访问控制
a) httpd -M | grep status #确认模块是否加载,如未加载在httpd.conf主配置文件找到以下字段取消注释,然后重载服务。
LoadMoudule status_module modules/mod_status.so
b) vim /etc/httpd/conf.d/www.conf #编辑配置文件,在www1虚拟主机内添加一下内容
<Location /server-status>
SetHandlerserver-status
AuthType basic
AuthNAME"only tom"
AuthUserfile/etc/httpd/conf/.htpw
Require user tom
</Location>
c) 为tom 用户创建访问密码
htpasswd -m -c /etc/httpd/conf/.htpw tom
d) 重载服务测试
service httpd reload
http://www1.abc.com/server-status
三、为www1配置为https
A) 创建CA
(umask077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
openssl req -new -x509 -key/etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem
touch /etc/pki/CA/index.txt
echo 01 > /etc/pki/CA/serial
B) 为https制作证书
a)创建保存秘钥的文件夹
mkdir /etc/httpd/ssl
b) 生成httpd秘钥
(umask 077;openssl genrsa -out/etc/httpd/ssl/httpd.key 2048)
c)生成证书请求文件
openssl req -new -key/etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr
d)CA签发证书
openssl ca -in /etc/httpd/ssl/httpd.csr-out /etc/httpd/ssl/httpd.crt
C) 配置https
a) 安装必要的rpm包
yum -y install mod_ssl
b) 编辑配置文件
vim /etc/httpd/conf.d/ssl.conf
<VirtualHost172.16.19.11:443>
DocumentRoot"/var/www/www1"
ServerName www.abc.com:443
SSLCertificateFile/etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile/etc/httpd/ssl/httpd.key
D) 重启测试服务
service httpd restart