配置vhost、https、重定向

配置vhost、https、重定向

一、配置虚拟主机
httpd服务在实际应用中有这样一种场景;我们有一台服务器,但是想挂多个网站,按照上面的配置方式就无法实现。那么我们就可以通过配置虚拟主机的方式实现一个服务器上运行多个网站,每个网站都是一个虚拟主机;虚拟主机其实就是通过httpd服务访问同一个服务器上的不同站点。

虚拟主机有三类:

相同IP不同端口
不同IP相同端口
相同IP相同端口不同域名
注意:虚拟主机的配置可以写在主配置文件;也可以将配置写在扩展配置文件,扩展配置文件需要自行创建。

准备工作

[root@192 ~]# dnf -y install httpd    //安装httpd服务
[root@192 ~]# systemctl stop firewalld.service     //临时关闭防火墙,立即生效
[root@192 ~]# systemctl disable firewalld.service
[root@192 ~]# setenforce 0
[root@192 ~]# systemctl restart httpd      //启动httpd服务
[root@192 ~]# systemctl enable httpd       //把httpd服务设置为开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
访问测试:

配置相同IP不同端口
//搜索vhost的模板文件
[root@192 ~]# find / -name "*vhosts.conf"
/usr/share/doc/httpd/httpd-vhosts.conf
//进入到可放置虚拟主机配置文件的目录
[root@192 ~]# cd /etc/httpd/conf.d/
//把模板文件拷贝至目录下
[root@192 conf.d]# cp /usr/share/doc/httpd/httpd-vhosts.conf ./
[root@192 conf.d]# vim httpd-vhosts.conf
[root@192 conf.d]# cat httpd-vhosts.conf      //配置内容如下
<VirtualHost *:80>         //指定该网站的IP地址与端口号
    DocumentRoot "/var/www/html/yzxfj"     //存放网页内容的根目录
    ServerName www.yf.com            //指定域名
    ErrorLog "/var/log/httpd/yzxfj_log/error_log"     //错误日志文件位置
    CustomLog "/var/log/httpd/yzxfj_log/access_log" common     //访问日志文件位置
</VirtualHost>

Listen 82            //监听82端口
<VirtualHost *:82>
    DocumentRoot "/var/www/html/tk"
    ServerName www.yf.com
    ErrorLog "/var/log/httpd/tk_log/error_log"
    CustomLog "/var/log/httpd/tk_log/access_log" common
</VirtualHost>

//创建两台虚拟主机网页内容存放的目录并把属主属组修改为apache
[root@192 conf.d]# cd /var/www/html/
[root@192 html]# ls
[root@192 html]# mkdir yzxfj tk
drwxr-xr-x. 2 root root 6 Jul 22 14:56 yzxfj
drwxr-xr-x. 2 root root 6 Jul 22 14:56 tk
[root@192 html]# chown -R apache.apache yzxfj
[root@192 html]# chown -R apache.apache tk
[root@192 html]# ll
total 0
drwxr-xr-x. 2 apache apache 6 Jul 22 14:56 yzxfj
drwxr-xr-x. 2 apache apache 6 Jul 22 14:56 tk

//获取网页内容
[root@192 html]# mv /root/feijiedazhan.zip ./    //把源码包移到网页存放目录
[root@192 html]# mv /root/坦克.zip ./
[root@192 html]# unzip feijiedazhan.zip ; unzip 坦克.zip    //解压源码包
[root@192 html]# ls                                //查看解压出的目录和文件
Battle_City  feijiedazhan.zip  yzxfj  HTM
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值