Linux静态站点Apache

一、Apache简介
在这里插入图片描述

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。
二、Apache基础
1、Apache官网: www.apache.org
2、软件包名称: httpd
3、服务端口: 80/tcp(http)
4、主配置文件: /etc/httpd/conf/httpd.conf
5、子配置文件:/etc/httpd/conf.d/*.conf
6、网站发布目录:/var/www/html 网站源代码默认位置
三、安装Apache
1、安装
[root@localhost ~]# yum -y install httpd
2、启动
[root@localhost ~]# systemctl start httpd
3、查看服务状态
[root@localhost ~]# systemctl status httpd
4、开机自启
[root@localhost ~]# systemctl enable httpd
5、关闭防火墙
[root@localhost ~]# systemctl stop firewalld
6、关闭selinux
[root@localhost ~]# setenforce 0
7、关闭防火墙
[root@localhost ~]# systemctl stop firewalld
8、查看版本
[root@localhost ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
四、Apache配置虚拟主机
服务器端 192.168.64.140
客户端
1、目的
虚拟主机VirtualHost作用:在一台物理服务器上运行多个网站
2、配置虚拟主机目标
在一台服务器上,实现两个网站的架设
网站域名              网站资源存放目录
www.a.org           /var/www/html/a.org
www.b.org           /b.org

3、环境
web服务器 192.168.64.130
客户机        192.168.64.129
真机            10.8.161.66
4、www.a.org站点设置
(1)准备网站源码(网页)目录
[root@localhost ~]# mkdir /var/www/html/a.org
[root@localhost ~]# vim /var/www/html/a.org/index.html

a.com.com.com

(2)创建a.org的网站配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/a.org.conf

<VirtualHost *:80>
ServerName www.a.org
DocumentRoot /var/www/html/a.org
</VirtualHost>
注释
VirtualHost-->代表某个虚拟主机;*-->表示IP地址;80-->表示端口号
   ServerName       www.a.org  -->服务器起个名字
      DocumentRoot       /var/www/html/a.org -->网站的根目录

(3)检测配置文件语法,重启服务
[root@localhost ~]# httpd -t
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName’ directive globally to suppress this message
Syntax OK
//AH00558没有语法错误
[root@localhost ~]# systemctl restart httpd
5、www.b.org站点设置
(1)准备网站源码(网页)目录
[root@localhost ~]# mkdir /b.org
[root@localhost ~]# vim /b.org/index.html
b.org.org.org
(2)创建b.org的网站配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/b.org.conf

<VirtualHost *:80>
ServerName www.b.org
DocumentRoot /b.org
</VirtualHost>
<Directory "/b.org">
Require all granted
</Directory>
注释:Apache默认网站发布目录为/var/www/html,当自定义网站发布目录时,需要授权
 Directory  "/b.org"--> 目录授权,仅在网站主目录非“/var/www/html”时操作
         Require   all    granted 允许所有的“网站”的访问

(3)检测配置文件语法,重启服务
[root@localhost ~]# httpd -t
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName’ directive globally to suppress this message
Syntax OK
[root@localhost ~]# systemctl restart httpd
6、虚拟客户端 192.168.64.129
(1)Linux客户端域名解析
[root@localhost ~]# vim /etc/hosts
192.168.64.130 www.a.org //填写web服务器的IP
192.168.64.130 www.b.org //填写web服务器的IP
(2)Linux客户端测试网站可用性 字符浏览器
[root@localhost ~]# yum -y install elinks
[root@localhost ~]# elinks http://www.a.org

在这里插入图片描述
[root@localhost ~]# elinks http://www.b.org
在这里插入图片描述
(3)图形界面测试
通过火狐浏览器,分别访问两个网站地址
7、真机客户端 10.8.161.66
(1)Windows客户端域名解析
在这里插入图片描述

在这里插入图片描述
(2)windows客户端测试网站可用性
打开真机的运行窗口,输入cmd(win键+R键快捷键)

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值