虚拟服务器上安装apach,Yum安装httpd(apache)并设置虚拟主机

Yum安装httpd(apache)并设置虚拟主机

httpd(apache)以其功能丰富,安全稳定,广为使用

安装httpd

对于CentOS8:

dnf -y install httpd

对于CentOS7:

yum -y install httpd

如果出错检查检查一下网络和yum源,如何更换yum源到阿里源

下面设置两个虚拟主机

虚拟主机可以让一个web服务器服务多个网站,每个网站可以有不同的设置,不同的语言,并且有独立的日志

这里假设两个主机分别为

game.shaochenfeng.com

map.shaochenfeng.com

新建配置文件

注意要以conf为扩展名

vim /etc/httpd/conf.d/virtual.conf

内容为

ServerName game.shaochenfeng.com

DocumentRoot /var/www/game.shaochenfeng.com

DirectoryIndex index.html

ErrorLog logs/game.shaochenfeng.com.error.log

TransferLog logs/game.shaochenfeng.com.log

Require all granted

ServerName map.shaochenfeng.com

DocumentRoot /var/www/map.shaochenfeng.com

DirectoryIndex index.html

ErrorLog logs/map.shaochenfeng.com.error.log

TransferLog logs/map.shaochenfeng.com.log

Require all granted

其中第一行中的 指定了监听的端口和主机范围

ServerName 监听的域名

DocumentRoot 网站根目录

DirectoryIndex 网站默认文档

ErrorLog 错误日志

TransferLog 访问日志

后面一部分 对网站目录进行设置

保存并退出

创建虚拟主机的主目录和日志目录

mkdir /var/www/game.shaochenfeng.com

mkdir /var/www/map.shaochenfeng.com

#将你的网站文件复制到上面对应的目录

chown apache:apache -R /var/www/game.shaochenfeng.com # httpd运行在apache用户下,所以要给网站文件授予权限

chown apache:apache -R /var/www/map.shaochenfeng.com

启动并开机启动httpd

systemctl enable httpd # 设置httpd开机启动

systemctl start httpd # 启动httpd

systemctl status httpd # 查看httpd状态

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值