网站制作技巧017,网站购买域名之后再怎么做,wordpress设置静态页面,公司的网站链接找谁做1 Apache虚拟主机的实现方式有3种。 基于IP的虚拟主机基于端口的虚拟主机基于域名的虚拟主机 2.1 启用虚拟主机的准备工作 2.1.1安装httpd [rootmail httpd]# yum install httpd -y 2.1.2禁用默认的主机模式 [rootmail httpd]# vim /etc/httpd/conf/httpd.conf
注释下面这行内容… 1 Apache虚拟主机的实现方式有3种。 基于IP的虚拟主机基于端口的虚拟主机基于域名的虚拟主机 2.1 启用虚拟主机的准备工作 2.1.1安装httpd [rootmail httpd]# yum install httpd -y 2.1.2禁用默认的主机模式 [rootmail httpd]# vim /etc/httpd/conf/httpd.conf
注释下面这行内容
#DocumentRoot /var/www/html 2.2基于IP的虚拟主机配置 2.2.1为主机添加多个IP [rootlocalhost conf.d]# ip addr show dev eth0 #查看原有IP
2: eth0: BROADCAST,MULTICAST,UP,LOWER_UP mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:77:77:7d brd ff:ff:ff:ff:ff:ffinet 192.168.137.200/24 brd 192.168.137.255 scope global eth0inet6 fe80::20c:29ff:fe77:777d/64 scope link valid_lft forever preferred_lft forever
[rootlocalhost conf.d]# ip addr add 192.168.137.201/24 dev eth0 #添加一个IP
[rootlocalhost conf.d]# ip addr show dev eth0 #查看添加后的IP信息 此时有2个IP地址了。 200,201
2: eth0: BROADCAST,MULTICAST,UP,LOWER_UP mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:77:77:7d brd ff:ff:ff:ff:ff:ffinet 192.168.137.200/24 brd 192.168.137.255 scope global eth0inet 192.168.137.201/24 scope global secondary eth0inet6 fe80::20c:29ff:fe77:777d/64 scope link valid_lft forever preferred_lft forever 2.2.2添加虚拟主机配置文件 [rootmail conf.d]# cd /etc/httpd/conf.d/ #进入配置目录
[rootmail conf.d]# vim virtualhost.conf #创建一个配置文件 编辑内容如下
[rootmail conf.d]# cat virtualhost.conf #查看并检查配置文件
VirtualHost 192.168.137.200:80DocumentRoot /var/www/test200ServerName www.test200.com
/VirtualHostVirtualHost 192.168.137.201:80DocumentRoot /var/www/test201ServerName www.test201.com
/VirtualHost [rootmail conf.d]# cd /var/www #切换目录
[rootmail www]# mkdir test200 test201 #创建目录
[rootmail www]# echo test200 ./test200/index.html #创建IP为200的主页
[rootmail www]# echo test201 ./test201/index.html #创建IP为200的主页 2.2.3测试 [rootlocalhost www]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the servers fully qualified domain name, using localhost.localdomain for ServerName[ OK ]
我们这里使用elinks进行测试 当然用浏览器测试是一样的
[rootlocalhost conf]# elinks -source 192.168.137.200
test200
[rootlocalhost conf]# elinks -source 192.168.137.201
test201 2.3基于端口的虚拟主机配置 2.3.1在主配置文件添加监听端口 [rootlocalhost conf]# vim /etc/httpd/conf/httpd.conf
在原有行Listen 80行的基础上 在添加一行
Listen 8080 2.3.2添加8080的端口虚拟配置 [rootlocalhost conf.d]# cat virtualhost.conf
VirtualHost 192.168.137.200:80DocumentRoot /var/www/test200ServerName www.test200.com
/VirtualHostVirtualHost 192.168.137.201:80DocumentRoot /var/www/test201ServerName www.test201.com
/VirtualHost
#下面的内容是在上面的配置的基础上添加的。
VirtualHost 192.168.137.201:8080DocumentRoot /var/www/test201-8080ServerName www.test201-8080.com
/VirtualHost [rootlocalhost conf.d]# cd /var/www/ #切换目录
[rootlocalhost www]# mkdir test201-8080 #创建目录
[rootlocalhost www]# echo test201-8080 ./test201-8080/index.html #创建主页 2.3.2测试 [rootlocalhost www]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the servers fully qualified domain name, using localhost.localdomain for ServerName[ OK ]
[rootlocalhost conf]# elinks -source 192.168.137.201:80
test201
[rootlocalhost conf]# elinks -source 192.168.137.201
test201
[rootlocalhost conf]# elinks -source 192.168.137.201:8080
test201-8080 2.4基于域名的虚拟主机配置 2.4.1 添加域名的虚拟主机配置 [rootlocalhost conf.d]# vim virtualhost.conf #编辑虚拟主机配置文件
[rootlocalhost conf.d]# cat virtualhost.conf #内容如下 红色部分是在上面的基础上添加的
NameVirtualHost 192.168.137.200:80
VirtualHost 192.168.137.200:80DocumentRoot /var/www/test200ServerName www.test200.com
/VirtualHostVirtualHost 192.168.137.200:80DocumentRoot /var/www/test200netServerName www.test200.net
/VirtualHostVirtualHost 192.168.137.201:80DocumentRoot /var/www/test201ServerName www.test201.com
/VirtualHostVirtualHost 192.168.137.201:8080DocumentRoot /var/www/test2018080ServerName www.test2018080.com
/VirtualHost [rootlocalhost conf.d]# !ser
service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the servers fully qualified domain name, using localhost.localdomain for ServerName[ OK ] [rootlocalhost conf.d]# cd /var/www #切换目录
[rootlocalhost www]# mkdir test200net #创建目录
[rootlocalhost www]# echo test200net ./test200net/index.html #创建主页 2.4.2 测试 2.4.2.1 添加域名解析 这里我们没有提供dns去解析简单的使用hosts文件区解析就可以了。 [rootlocalhost www]# vim /etc/hosts 编辑hosts文件 添加两行
[rootlocalhost www]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.137.200 www.test200.com
192.168.137.200 www.test200.net 接下来就可以测试了 [rootlocalhost www]# elinks -source http://www.test200.com #测试.com域
test200
[rootlocalhost www]# elinks -source http://www.test200.net #测试.net域
test200net