Apache虚拟主机案例演示

简介:

基于dns的实验拓扑上构建网站服务器,这里以apache来搭建

首先进入科普:

url=协议+主机地址或域名+资源地址

www服务使用排名  查询网站https://w3techs.com/

1.Apache49.9%-0.5%  中小型静态web主流,web服务器中老大

2.Nginx33.4%+0.7%  大型新兴今天web主流,web服务器中的初生牛犊

3.Microsoft-IIS11.3%-0.2%  微软web服务器

4.LiteSpeed2.5%

5.Google Servers1.2%-0.1%

 

动态web服务

Microsoft-IIS  微软web服务器  asp

tomcat  java容器主流  jsp

resin  java容器主流

php   php程序的解析容器

 

apache稳定,安全,配置简单,速度快,应用广泛,可以做负载均衡,处理

小文件能力不如nginx

 

apache下载地址:www.apache.org

 



源码包与二进制包选择

1)对外提供服务选择源码包(lamp),因为效率更高

2)软件包是linux底层支持包,选择二进制包(gcc编译器),因为安装方便

相关文件

Apache配置文件

源码包安装/usr/local/apache2/etc/httpd.conf

Usr/local/apache/etc/extra/*.conf

 

Rpm包安装/etc/httpd/conf/httpd.conf

 

网页保存位置

源码包安装:/usr/local/apache2/htdocs/

Rpm包安装:/var/www/html/

 

日志保存位置

源码包安装:/usr/local/apache2/logs

Rpm包安装:/var/log/httpd/

 

注意日志的轮替

 

关闭服务:/usr/local/apache2/bin/apachectl stop

开启服务:/usr/local/apache2/bin/apachectl start

注意:不能直接restart

基本配置

ServerRoot       apache主目录

Listen          监听端口

LoadModule     加载的相关模块

User            伪用户

Group           伪用户组

ServerAdmin      管理员邮箱

ServerName       服务器名

DirectoryIndex     默认主页文件

ErrorLog          错误日志

LogLevel          日志等级

CustomLog        正确访问日志

Include           加载子配置文件

主页目录及权限

网页主目录DocunmentRoot /usr/local/apache2//htdocs

Apache安全性就体现在directory权限

<Directory /usr/local/apache2//htdocs>

所有网页必须必须定义放在这个目录下才可以访问

Options   真正的权限

一般定义为followsymlinks (准许经过此目录链接到其他目录)

None:没有任何额外权限

All:所有权限

Indexes:浏览权限

 

AllowOverride  子权限文件开关(定义是否允许目录下.htaccess文件中的权限生效)

None:htaccess文件中的权限不生效

All:文件中所有权限都生效

 

Require  访问控制列表

<RequireALL>

Require all granted

Require ip 192.168.1.1

 

</RequireALL>

仅仅允许ip192.168.1.1的主机访问

<RequireALL>

Require all granted

Require ip 192.168.1.0/24

仅仅允许ip192.168.1.0/24网络的主机访问

</RequireALL>

 

<RequireALL>

Require all granted

Require not ip 192.168.1.2

 

 

</RequireALL>

禁止192.168.1.2的主机访问,其他的都允许访问

 

</Directory>

 

 

Require all granted 允许所有访问

Require all denied 拒绝所有访问

 


实操阶段:

 

源代码安装Apache服务器

 

1. httpd源代码包复制到linux 系统/usr/local/src目录下,并解压


实验拓扑图:

wKiom1jwf4jQ_rPcAAAzkKGHijw535.png-wh_50 

安装gcc  gcc+

yum -y install gcc-c++

 yum -y install gcc

 

 

httpd源代码包复制到linux 系统/usr/local/src目录下,并解压

cd /usr/local/src

tar xzf httpd-2.2.9.tar.gz

cd httpd-2.2.9

./configure --prefix=/usr/local/apache2/  --enable-so  --enable-rewrite

make && make install

cd /usr/local/apache2/

 vim conf/httpd.conf

97 ServerName www.winsnet.com:80   //更改这一行为你的域名地址

关闭服务:/usr/local/apache2/bin/apachectl stop

开启服务:/usr/local/apache2/bin/apachectl start

注意:不能直接restart

                      Apache添加为系统服务

 

Apache添加为系统服务

cp -ap /usr/local/apache2/bin/apachectl /etc/init.d/apachectl

 vim /etc/init.d/apachectl

 2 #description: apache server     //添加这两行

  3 #chkconfig:35 61 61

 

 chkconfig --add apachectl

chkconfig --list apachectl    //从输出结果来看已经添加进系统服务,从此就可以用service来管理了

 service  apachectl start|stop

 

                      虚拟主机

1. 准备www.baby.comwww.kuparts.com两个虚拟网站的主目录及网站首页

 cd /usr/local/apache2/htdocs

 

 mkdir baby kuparts     //创建两个虚拟网站目录

 cd lab/

 vim index.html   //将网页源代码传到这里

 This is lab

 

 cd ..

 cd winsnet/

 vim index.html  //将网页源代码传到这里

 this is winsnet

 

 cd /usr/local/apache2/      //编辑配置文件

 vim conf/httpd.conf

 

388 Include conf/extra/httpd-vhosts.conf   //把这一行注释去掉

 

 cd /usr/local/apache2/conf/extra    //编辑子配置文件

 vim httpd-vhosts.conf

<Directory "usr/local/apache2/htdos/baby">   //加入directory权限

Options Indexes

AllowOverride None

Require all granted

</Directory>

 

<Directory "usr/local/apache2/htdos/kuparts">

Options Indexes

AllowOverride None

Require all granted

</Directory>

 

<VirtualHost *:80>      //编辑配置文件

    ServerAdmin 98376587@qq.com   //自己邮箱地址

    DocumentRoot "/usr/local/apache2/htdocs/baby"  
//网页主目录

    ServerName www.baby.com    //网站完整域名

#    ServerAlias www.dummy-host.example.com   //网站别名

    ErrorLog "logs/baby-error_log"     //错误日志

    CustomLog "logs/baby-access_log" common   //正确日志

</VirtualHost>

 

<VirtualHost *:80>

    ServerAdmin 983765387@qq.com

  DocumentRoot "/usr/local/apache2/htdocs/kuparts"  
//网页主目录

    ServerName www.kuparts.com    //网站完整域名

#    ServerAlias www.dummy-host.example.com   //网站别名

    ErrorLog "logs/kuparts-error_log"     //错误日志

    CustomLog "logs/kuparts-access_log" common   //正确日志

</VirtualHost>



                     

service  apachectl  stop

service  apachectl  start



测试结果

wKiom1jwgsmAFoSwAAcHynBqwFE493.png-wh_50

wKioL1jwgtGD2ZLjAASlnqCgvTw533.png-wh_50


本文转自    探花无情   51CTO博客,原文链接:http://blog.51cto.com/983865387/1916042


相关实践学习
基于函数计算快速搭建Hexo博客系统
本场景介绍如何使用阿里云函数计算服务命令行工具快速搭建一个Hexo博客。
相关文章
|
4月前
|
存储 算法 数据挖掘
带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(2)
带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(2)
|
4月前
|
存储 SQL 大数据
带你读《Apache Doris 案例集》—— 01 招商信诺人寿 基于 Apache Doris 统一 OLAP 技术栈实践(1)
带你读《Apache Doris 案例集》—— 01 招商信诺人寿 基于 Apache Doris 统一 OLAP 技术栈实践(1)
142 0
|
4月前
|
存储 运维 关系型数据库
带你读《Apache Doris 案例集》——04 星云零售信贷 基于 Apache Doris 的 OLAP 演进之路(1)
带你读《Apache Doris 案例集》——04 星云零售信贷 基于 Apache Doris 的 OLAP 演进之路(1)
带你读《Apache Doris 案例集》——04 星云零售信贷  基于 Apache    Doris 的 OLAP  演进之路(1)
|
4月前
|
存储 安全 数据挖掘
带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(1)
带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(1)
|
4月前
|
SQL 缓存 监控
带你读《Apache Doris 案例集》——03 Apache Doris 在金融壹账通指标中台的应用实践(2)
带你读《Apache Doris 案例集》——03 Apache Doris 在金融壹账通指标中台的应用实践(2)
带你读《Apache Doris 案例集》——03  Apache   Doris  在金融壹账通指标中台的应用实践(2)
|
4月前
|
SQL 运维 数据挖掘
带你读《Apache Doris 案例集》——03 Apache Doris 在金融壹账通指标中台的应用实践(1)
带你读《Apache Doris 案例集》——03 Apache Doris 在金融壹账通指标中台的应用实践(1)
|
4月前
|
存储 监控 安全
带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(1)
带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(1)
|
4月前
|
SQL 存储 安全
带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(2)
带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(2)
105 0
|
1月前
|
存储 测试技术 API
Apache Hudi 负载类Payload使用案例剖析
Apache Hudi 负载类Payload使用案例剖析
27 4
|
4月前
|
Apache
带你读《Apache Doris 案例集》—— 前言
带你读《Apache Doris 案例集》—— 前言
149 0

热门文章

最新文章

推荐镜像

更多