admin管理员组

文章数量:1794759

Apache之搭建静态网站

Apache之搭建静态网站

一:安装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网站 1.准备源码

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

2.网站配置文件

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

测试 客户端域名解析

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

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

yum install -y elinks elinks www.hello

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

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

2.网站配置文件

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

测试 客户端域名解析

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

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

yum install -y elinks elinks www.world

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

Apache之搭建动态网站(Discuz)

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

本文标签: 静态网站Apache