linux 安装apache发布网站

安装apache服务并启动

[root@localhost ~]# yum install -y httpd
[root@localhost ~]# systemctl start httpd.service 

测试apcahe是否安装成功

在这里插入图片描述

相关目录

/etc/httpd/conf:该目录存放Apache服务器的配置文件
/var/www/html:该目录是Apache服务器的默认站点根目录
/etc/httpd/logs:Apache服务器的日志文件目录

单个网站的发布

网站放到/var/www/html/目录下,并修改配置文件
我的网站主目录为html下面的super

[root@localhost super]# vim /etc/httpd/conf/httpd.conf 

在这里插入图片描述
检查并重启配置文件

[root@localhost super]# httpd -t #检查配置文件
[root@localhost super]# systemctl restart httpd.service 

现在输入IP地址便可以访问到网站
在这里插入图片描述
为了方便记忆管理,我们将ip和域名相对应

[root@localhost ~]# vim /etc/hosts

在这里插入图片描述
现在就可以用域名访问网站
在这里插入图片描述

多个网站的发布

将两个网站放到/var/www/html目录下
在这里插入图片描述
在/etc/httpd/conf目录下新建vhost目录,创建super 和man的配置文件

编辑super网站配置文件

[root@localhost vhost]# vim super.conf
<VirtualHost 192.168.0.103>
ServerName www.super.com
DocumentRoot /var/www/html/super
<Directory “/var/www/html/super”>
Options Indexes FollowSymLinks   #显示网页文件列表 
AllowOverride NOne               #忽略.htaccess 文件 
Require all granted              #允许所有 
</Directory>
</VirtualHost>

在这里插入图片描述

编辑man网站配置文件

[root@localhost vhost]# vim man.conf
<VirtualHost 192.168.0.103>
ServerName www.man.com
DocumentRoot /var/www/html/man
<Directory “/var/www/html/man”>
Options Indexes FollowSymLinks   #显示网页文件列表 
AllowOverride NOne               #忽略.htaccess 文件 
Require all granted              #允许所有
</Directory>
</VirtualHost>

在这里插入图片描述
修改主配置文件,在末尾添加Include conf/vhost/*.conf

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

在这里插入图片描述
添加域名到hosts

在这里插入图片描述

检查配置文件并重启服务

[root@localhost ~]# httpd -t
[root@localhost ~]# systemctl restart httpd

测试验证
在这里插入图片描述
如不能访问网站排查步骤
检查两个分站配置文件是否正确,尤其指定网站的路径
检查主配置文件是否指定分站配置的路径
hosts文件是否正确
配置文件中是否给权限允许访问
如上诉步骤依然不能解决:尝试关闭安全机制和防火墙

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值