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键快捷键)

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在 Linux 上搭建 Apache 静态网站,可以按照以下步骤操作: 1. 安装 Apache 在终端中运行以下命令安装 Apache: sudo apt-get update sudo apt-get install apache2 2. 创建网站目录 在 Apache 的默认设置中,网站文件存放于 /var/www/html 目录。可以在该目录下创建一个新的子目录,作为你的网站根目录。 sudo mkdir /var/www/html/mywebsite 3. 配置网站文件 将你的网站文件(如 HTML、CSS、JavaScript 文件等)放在刚刚创建的网站目录中。若网站有默认首页(如 index.html),则需将其重命名为 index.html。 sudo mv /path/to/website/files/* /var/www/html/mywebsite/ sudo mv /var/www/html/mywebsite/myindex.html /var/www/html/mywebsite/index.html 4. 配置网站权限 确保 Apache 可以读取和访问你的网站文件。 sudo chown -R www-data:www-data /var/www/html/mywebsite/ sudo chmod -R 755 /var/www/html/mywebsite/ 5. 配置虚拟主机 如果需要在 Apache 中配置多个网站,需要使用虚拟主机。创建一个新的虚拟主机配置文件。 sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mywebsite.conf 打开新文件并编辑以下行,将其中的 example.com 替换为你的网站域名或 IP 地址。 ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/html/mywebsite 6. 激活虚拟主机 运行以下命令激活新创建的虚拟主机配置文件。 sudo a2ensite mywebsite.conf 7. 重新启动 Apache 运行以下命令使 Apache 加载新配置并重新启动。 sudo systemctl reload apache2 至此,Apache 静态网站已经搭建完成。可以通过浏览器访问你的网站,地址为 http://localhost 或者 http://服务器 IP。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值