【操作】【CentOS_7】安装配置 Apache 服务器,完成单站点、虚拟目录、多站点的发布

参考:https://blog.csdn.net/az44yao/article/details/8750400

1.下载httpd并开启Apache 服务

(1)下载httpd

yum install httpd

(2)开启httpd服务

systemctl start httpd

(3)关闭防火墙

systemctl stop firewalld

(4)打开浏览器,在地址栏中输入 127.0.0.1:800 结果如下(端口转发 800->80)在这里插入图片描述

2.单站点网络发布

(1)切换到网页目录下

cd /var/www/html/   (切换到此目录)

(2)创建index.html文件,并写入一些内容(如下图)

touch index.html   (创建文件)
vi index.html   (编辑文件)

在这里插入图片描述

(3)重启Apache服务

systemctl restart httpd

(4)打开浏览器,在地址栏中输入 127.0.0.1:800/index.html 结果如下

在这里插入图片描述

3.虚拟目录的发布

(1)切换到网页目录下

cd /var/www/

(2)分别创建alias1和alias2两个目录,并写入相应内容(此处以alias1为例)

mkdir alias1
cd /alias1
touch index.html
vi index.html

在这里插入图片描述

(3)创建相应的配置文件

cd /etc/httpd/
mkdir test-conf.d
cd test-conf.d/
touch test.conf
vi test.conf

(4)复制下面的内容到上面的配置文件内

  • #Documentroot:站点目录
  • #Alias:映射URL到文件系统的特定区域
  • #Directory:定义目录访问权限
  • #ServerName:访问域名
  • #ServerAlias:给虚拟主机增加多个域名,上面网址的别名
  • #<Directory “/”>:权限设置,标签中的地址是相对于DocumentRoot的
<VirtualHost *:80>
ServerAdmin root@localhost
Documentroot /var/www/
Alias /index /var/alias1
Alias /index1 /var/alias2
<Directory "/var/www/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

(5)引用上面的配置文件

vi /etc/httpd/conf/httpd.conf
IncludeOptional test-conf.d/*.conf   (将此句复制到文件中)

(6)重启Apache服务

systemctl restart httpd

(7)打开浏览器进行网页访问测试

在这里插入图片描述

在这里插入图片描述

4.多端口发布(利用3中的目录以及文件进行操作)

(1)这里仍然使用3中所创建的alias1和alias2两个目录文件为例

(2)打开3中配置文件

vi /etc/httpd/test-conf.d/test.conf

(3)复制下面的内容到上面的配置文件内

<VirtualHost *:80> 
ServerAdmin root@localhost 
DocumentRoot /var/www/alias1 
<Directory "/var/www/alias1"> 
Options FollowSymLinks 
AllowOverride All 
Require all granted 
</Directory> 
</VirtualHost> 
<VirtualHost *:82> 
ServerAdmin root@localhost 
DocumentRoot /var/www/alias2 
<Directory "/var/www/alias2"> 
Options FollowSymLinks 
AllowOverride All 
Require all granted  
</Directory> 
</VirtualHost> 

(4)添加监听端口如下图

vi /etc/httpd/conf/httpd.conf

在这里插入图片描述

(5)配置端口转发 800->80,802->82
在这里插入图片描述

(6)关闭selinux防火墙(会阻断端口)

setenforce 0

(7)重启重启Apache服务

systemctl restart httpd

(8)打开浏览器进行网页访问测试

在这里插入图片描述

在这里插入图片描述

5.多域名发布

(1)这里仍然使用3中所创建的alias1和alias2两个目录文件为例

(2)编辑配置文件

vi /etc/httpd/test-conf.d/test.conf

(3)将下列代码复制进去

<VirtualHost *:80> 
ServerAdmin root@localhost 
ServerName www.yi.com
DocumentRoot /var/www/alias1
<Directory "/var/www/alias1"> 
Options FollowSymLinks 
AllowOverride All 
Require all granted 
</Directory> 
</VirtualHost> 
<VirtualHost *:80> 
ServerAdmin root@localhost 
ServerName www.two.com
DocumentRoot /var/www/alias2 
<Directory "/var/www/alias2"> 
Options FollowSymLinks 
AllowOverride All 
Require all granted  
</Directory> 
</VirtualHost> 

(4)重启重启Apache服务

systemctl restart httpd

(5)编辑本地 hosts 文件,其文件路径为 C:\Windows\System32\drivers\etc\hosts,hosts 文件,添加下图内容

在这里插入图片描述

(6)打开浏览器进行网页访问测试

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值