Apache之搭建静态网站

45 篇文章 5 订阅
本文详细介绍了如何在Linux系统中安装Apache服务器,包括启动、状态检查、设置开机自启以及关闭防火墙和SELinux。接着,通过创建VirtualHost配置,搭建了两个静态网站www.hello.org和www.world.org,并进行了客户端的测试验证。同时,强调了配置文件中避免使用中文注释的重要性。
摘要由CSDN通过智能技术生成

一:安装Apache

(1)安装

yum -y install httpd

(2)启动

systemctl start httpd

(3)查看服务状态

systemctl status httpd

(4)设置开机自启

systemctl enable httpd

(5)关闭防火墙
(查看:systemctl status firewalld)
systemctl stop firewalld(临时关闭)
systemctl disable firewalld(永久关闭)
(6)关闭selinux(查看:getenforce (enfirce开启,permi放行,disable关闭))
selinux:保护服务器内部程序(ftp)对内部文件(/var/ftp)的访问(如:小黑屋))
setenforce 0(临时关闭)
vim /etc/selinux/config 修改为SLINUX=disable(永久关闭)
(7)查看http版本

httpd -v

在这里插入图片描述

二:搭建静态站点

VirtuallHost :在一台物理服务器上运行多个网站
搭建www.hello.org网站
1.准备源码

mkdir /var/www/html/hello.org
vim /var/www/html/hello.org/index.html
写入如下内容:
welcome,www.hello.org
:wq                                      #保存退出

2.网站配置文件

vim /etc/httpd/conf.d/hello.org.conf
写入如下内容:
<VirtualHost *:80>                      #某个虚拟主机
ServerName  www.hello.org               #服务器名
DocumentRoot  /var/www/html/hello.org   #网站的根目录
</VirtualHost>
:wq                                      #保存退出
httpd -t                                #检测配置文件的语法
systemctl restart httpd                 #重启httpd服务

在这里插入图片描述

测试
客户端域名解析

vim /etc/hosts
写入如下内容:
webf服务器ip地址(这个需要自己填)   www.hello.org
:wq                                      #保存退出

客户端测试网站可用性
1)图形测试-----火狐浏览器访问
2)字符测试-----elinks

yum install -y elinks
  elinks http://www.hello.org

在这里插入图片描述

搭建www.world.org网站
1.准备源码

mkdir /world.org
vim /world.org/index.html
写入如下内容:
welcome to www.world.org

2.网站配置文件

vim /etc/httpd/conf.d/world.org.conf
写入如下内容:
<VirtualHost *:80>          #某个虚拟主机
ServerName  www.world.org   #服务器名
DocumentRoot  /world.org    #网站的根目录
</VirtualHost>
<Directory "/world.org">    #目录
Require all granted         #授权(通常情况下用户只能访问/var/www/html/,其他目录不能访问)
</Directory>                #目录
:wq                         #保存退出

httpd -t                    #检测配置文件的语法
systemctl restart httpd     #重启httpd服务

测试
客户端域名解析

vim /etc/hosts
webf服务器ip地址   www.world.org
:wq                                      #保存退出

客户端测试网站可用性
1)图形测试-----火狐浏览器访问(当然也可以在windos中测试就需要进行域名解析C:\Windows\System32\drivers\etc\hosts文件)
2)字符测试-----elinks

yum install -y elinks
elinks http://www.world.org

在这里插入图片描述

注意事项:
在写网站配置文件时要注意不要写中文注释进去,不然可能会在检查语法时通不过。

Apache之搭建动态网站(Discuz)

感谢大家,点赞,收藏,关注,评论!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cat God 007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值