web服务httpd-2.2基于域名虚拟主机

web网站服务:

Apache著名的开源Web服务软件,由ASF自由软件基金负责维护操作

官方站点:http://httpd.apache.org/

http://www.netcraft.com/ 对各种Web软件的市场份额做了详细的统计

实验需求:

1、建立httpd服务,要求:
   (1) 提供两个基于名称的虚拟主机www1, www2;有单独的错误日志和访问日志 
   (2) 通过www1的/server-status提供状态信息,且仅允许tom用户访问
   (3) www2不允许192.168.0.0/24网络中任意主机访问
2、为上面的第2个虚拟主机提供https服务

实验环境:

Web Server: CentOS 6.7x86_64          IP:172.16.251.164

httpd-2.2.15-45.el6.centos.x86_64

客户端:CentOS 7.2x86_64                     IP:172.16.251.138

实验准备:

[[email protected] ~]# iptables –F                     //关闭防火墙

[[email protected] ~]# setenforce 0                   //关闭SeLinux

安装httpd:

[[email protected] ~]# yum -y install httpd

[[email protected] ~]# rpm -qc httpd                //查看安装httpd生成的配置文件

/etc/httpd/conf.d/welcome.conf

/etc/httpd/conf/httpd.conf

/etc/httpd/conf/magic

/etc/logrotate.d/httpd

/etc/sysconfig/htcacheclean

/etc/sysconfig/httpd

[[email protected] ~]# service httpd start

[[email protected] ~]# ss –tnl

LISTEN    0      128                          :::80

主配置文件:

[[email protected] conf]# cp -p httpd.confhttpd.conf.bak

[[email protected] httpd]# vim/etc/httpd/conf/httpd.conf

NameVirtualHost 172.16.251.164:80                 //启用虚拟主机

创建虚拟主机www1配置文件:

[[email protected] ~]# vim /etc/httpd/conf.d/v1.conf

<VirtualHost 172.16.251.164:80>

DocumentRoot /var/www/virt1

ServerNamewww1.a.com

ErrorLog logs/www1-error_log
       CustomLog logs/www1-access_log combined

<Location /server-status>

SetHandler server-status

AuthType basic

AuthName "Fortom"

AuthUserFile"/etc/httpd/conf/.htpasswd"

Require user tom

</Location>

</VirtualHost>

创建虚拟主机www2配置文件:

[[email protected] ~]# vim /etc/httpd/conf.d/v2.conf

<VirtualHost 172.16.251.164:80>

DocumentRoot /var/www/virt2

ServerNamewww2.a.com

ErrorLog logs/www2-error_log
       CustomLog logs/www2-access_log combined

<Directory"/var/www/virt2">

Options None

AllowOverride None

Order deny,allow

Deny from 192.168.0.0/24

</Directory>

</VirtualHost>

创建测试站点资源:

[[email protected] conf]# mkdir -pv/var/www/virt{1,2}

[[email protected] www]# echo "www1">> /var/www/virt1/index.html

[[email protected] www]# echo "www2" >>/var/www/virt2/index.html

创建tom用户文件:

[[email protected] conf]# htpasswd -cm/etc/httpd/conf/.htpasswd tom

[[email protected] conf]# httpd -t

Syntax OK

[[email protected] conf]# service httpd restart

客户端测试:

[[email protected] ~]# cat /etc/hosts

172.16.251.164        www1.a.com   www2.a.com

[[email protected] ~]# curl http://www1.a.com

www1

[[email protected] ~]# curl http://www2.a.com

www2

[[email protected] conf.d]# ll /var/log/httpd/

-rw-r--r--. 1 root root 11465 7月  17 12:33 www1-access_log

-rw-r--r--. 1 root root  3517 7月  17 12:33 www1-error_log

-rw-r--r--. 1 root root  2306 7月  17 10:25 www2-access_log

-rw-r--r--. 1 root root  1142 7月  17 10:17 www2-error_log

[[email protected] ~]# links http://www1.a.com/server-status

提供https服务:

1.建立私有CA

[[email protected] CA]# (umask 077; openssl genrsa-out private/cakey.pem 2048)

[[email protected] CA]# openssl req -new -x509 -keyprivate/cakey.pem -out cacert.pem

Country Name (2 letter code) [XX]:CN  
State or Province Name (full name) []:bj
Locality Name (eg, city) [Default City]:bj
Organization Name (eg, company) [Default Company Ltd]:ym
Organizational Unit Name (eg, section) []:Ops      
Common Name (eg, your name or your server‘s hostname) []:www2.a.com
Email Address []:[email protected]

[[email protected] CA]# touch index.txt

[[email protected] CA]# echo 01 > serial

2.申请证书:

[[email protected] CA]# mkdir -pv /etc/httpd/ssl

[[email protected] ssl]# (umask 077; openssl genrsa-out httpd.key 1024)

[[email protected] ssl]#  openssl req -new -key httpd.key -outhttpd.csr

Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:bj
Locality Name (eg, city) [Default City]:bj
Organization Name (eg, company) [Default Company Ltd]:ym
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server‘s hostname) []:www2.a.com
Email Address []:[email protected]

[[email protected] ssl]# cp httpd.csr /testdir/

3.CA签发证书,并将证书发送请求者

[[email protected] ssl]# openssl ca -in/tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt

[[email protected] ssl]# cp/etc/pki/CA/certs/httpd.crt /etc/httpd/ssl/

4.安装mod_ssl模块

[[email protected] conf.d]# httpd -M | grep ssl

[[email protected] conf.d]# yum -y install mod_ssl

[[email protected] conf.d]# rpm -ql mod_ssl

[[email protected] conf.d]# vim/etc/httpd/conf.d/ssl.conf

<VirtualHost 192.168.1.200:443>

DocumentRoot "/var/www/virt2"

ServerName www2.a.com:443

SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

[[email protected] conf.d]# service httpd restart

[[email protected] conf.d]# ss -tnl

LISTEN    0      128                          :::443

客户端测试:https://172.16.251.164:443

时间: 2024-10-13 11:59:30

web服务httpd-2.2基于域名虚拟主机的相关文章

基于域名虚拟主机及主站迁移

第二章实验(二):基于域名虚拟主机及主站迁移 1.配置BIND支持多域名解析:在实际工作中需要申请多个域名,并做好解析. 登录到192.168.100.100(已经提供了linuxfan.cn的解析) [[email protected] ~]# vim /var/named/chroot/etc/named.conf   ##在该文件末尾添加如下内容 zone "sggfu.com" IN { type master; file "sggfu.com.zone";

HTTPS+基于域名虚拟主机设置

#/etc/httpd/conf.d/ssl.conf #grep -v ^# /etc/httpd/conf.d/ssl.conf | grep -v ^$ NameVirtualHost 172.16.254.101:443 *********************定义基于域名虚拟主机 <VirtualHost 172.16.254.101:443> *********************baidu.comDocumentRoot "/var/www/html/baidu&

apache主配置文件模板和基于域名虚拟主机配置文件模板

1,主配置文件模板 # cat  httpd.conf ServerRoot "/usr/local/apache" Listen 80 LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_core_module modules/mod_authn_core.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule 

搭建基于域名虚拟主机

修改主配置文件 # cd /etc/httpd/conf.d/ # vim vhost.conf <VirtualHost *:80> DocumentRoot /var/www/wwwroot/myweb ServerName www.myweb.com ErrorLog logs/www.myweb.com-error_log CustomLog logs/www.myweb.com-access_log common </VirtualHost>

Apache服务器在80端口配置多域名虚拟主机的方法

我们在配置一台服务器的时候,如果只运行一个站点,往往过于浪费资源.Nginx和Apache都可以通过配置虚拟主机实现多站点.配置虚拟主机的方式主要有两种,一种是多个不同端口对应的多个虚拟主机站点,一种是同一端口对应多个不同域名的虚拟主机站点.这里我用80端口为例,在apache配置多个不同域名虚拟主机. 试验环境:windows+apache (linux+apache同理) 1.  虚拟机需要用到Rewrite,所以先编辑Apache的conf目录下的httpd.conf文件 掉Rewrite

linux web服务器(二) 基于域名,ip,端口的web虚拟主机

linux web服务器(二) 1 :搭建基于域名的虚拟主机     首先为两个网站搭建dns服务器,并新建区域,分别为:www.goole.com和www.baidu.com     2) 修改配置文件 3)    修改数据文件 4)    重启dns服务 5)    搭建两个网站 6:准备网页 7)打开虚拟主机配置文件,修改配置文件 8: 添加以下内容 9)    修改主配置文件,启用虚拟主机       Vi /usr/local/httpd/conf/httpd.conf  去掉前面的#

CentOS 7部署DNS主从复制及Apache域名虚拟主机

一.安装主DNS服务器 1.配置主DNS [[email protected] ~]# yum -y install bind bind-chroot bind-utils <!--安装DNS依赖程序--> [[email protected] ~]# cp /etc/named.conf /etc/named.conf.bak <!--备份主配置文件--> [[email protected] ~]# echo "" > /etc/named.conf

配置httpd结合php及默认虚拟主机

一.配置httpd支持php1?httpd的主配制文件: /usr/local/apache/conf/httd.conf1?在我们安装好httpd之后,会有一个提示set ServerName,我们进入以上这个配制文件,把Servername前面的#号去掉,然后注释掉一个php,这样就不会提示出错了.2?增加一行配制:Require all granted 如果不加这一行,访问是403我们要首先要ping 下80端口是不是通的,临时让linux防火墙开启80端口: iptables -I IN

HTTPS-SSL/TSL与SNI的关系以及同IP多域名虚拟主机的SSL/TSL认证

早期的SSLv2根据经典的公钥基础设施PKI(Public Key Infrastructure)设计,它默认认为:一台服务器(或者说一个IP)只会提供一个服务,所以在SSL握手时,服务器端可以确信客户端申请的是哪张证书. 但是让人万万没有想到的是,虚拟主机大力发展起来了,这就造成了一个IP会对应多个域名的情况.解决办法有一些,例如申请泛域名证书,对所有*.yourdomain.com的域名都可以认证,但如果你还有一个yourdomain.net的域名,那就不行了. 在HTTP协议中,请求的域名