欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

歡迎來到云服務器

服務器租用

Apache配置虛擬主機的三種實現方式 - 夢飛科技

不管你是進行Apache配置虛擬主機新加坡電信服務器 馬來西亞服務器,還是其他配置主機,啟用虛擬主機的準備工作是必不可少的,首先需要安裝httpd和禁用默認的主機模式。

安裝httpd:

[rootmail@ httpd]# yum install httpd -y

禁用默認的主機模式:

[root@mail httpd]# vim /etc/httpd/conf/httpd.conf

注釋下面這行內容

#DocumentRoot "/var/www/html"

接下來,開始Apache配置虛擬主機

一、基于IP的虛擬主機

1、為主機添加多個IP

[root@localhost conf.d]# ip addr show dev eth0            #查看原有IP

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:77:77:7d brd ff:ff:ff:ff:ff:ff

inet 192.168.137.200/24 brd 192.168.137.255 scope global eth0

inet6 fe80::20c:29ff:fe77:777d/64 scope link 

valid_lft forever preferred_lft forever

[root@localhost conf.d]# ip addr add 192.168.137.201/24 dev eth0        #添加一個IP

[root@localhost 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 1000

link/ether 00:0c:29:77:77:7d brd ff:ff:ff:ff:ff:ff

inet 192.168.137.200/24 brd 192.168.137.255 scope global eth0

inet 192.168.137.201/24 scope global secondary eth0

inet6 fe80::20c:29ff:fe77:777d/64 scope link 

valid_lft forever preferred_lft forever

2、添加虛擬主機配置文件

[root@mail conf.d]# cd /etc/httpd/conf.d/      #進入配置目錄

[root@mail conf.d]# vim virtualhost.conf       #創建一個配置文件, 編輯內容如下
[root@mail conf.d]# cat virtualhost.conf       #查看并檢查配置文件

<VirtualHost 192.168.137.200:80>

DocumentRoot "/var/www/test200"

ServerName    www.test200.com

</VirtualHost>

<VirtualHost 192.168.137.201:80>

DocumentRoot "/var/www/test201"

ServerName    www.test201.com

</VirtualHost>


[root@mail conf.d]# cd /var/www            #切換目錄

[root@mail www]# mkdir test200 test201    #創建目錄
[root@mail www]# echo test200 >>./test200/index.html #創建IP為200的主頁

[root@mail www]# echo test201 >>./test201/index.html #創建IP為200的主頁

3、接下來開始測試

[root@localhost www]#  service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName

[  OK  ]

我們這里使用elinks進行測試, 當然用瀏覽器測試是一樣的

[root@localhost conf]# elinks -source 192.168.137.200
test200
[root@localhost conf]# elinks -source 192.168.137.201

test201

二、基于端口的虛擬主機配置

1、在主配置文件添加監聽端口

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

在原有行Listen 80行的基礎上, 在添加一行

Listen 8080 

2、添加8080的端口虛擬配置

[root@localhost conf.d]# cat virtualhost.conf 

<VirtualHost 192.168.137.200:80>

DocumentRoot "/var/www/test200"

ServerName    www.test200.com

</VirtualHost>


<VirtualHost 192.168.137.201:80>

DocumentRoot "/var/www/test201"

ServerName    www.test201.com

</VirtualHost>

#下面的內容是在上面的配置的基礎上添加的。

<VirtualHost 192.168.137.201:8080>

DocumentRoot "/var/www/test201-8080"

ServerName    www.test201-8080.com

</VirtualHost>


[root@localhost conf.d]# cd /var/www/           #切換目錄

[root@localhost www]# mkdir test201-8080        #創建目錄

[root@localhost www]# echo "test201-8080" >>./test201-8080/index.html       #創建主頁

3、測試

[root@localhost www]#  service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]

[root@localhost conf]# elinks -source 192.168.137.201:80

test201

[root@localhost conf]# elinks -source 192.168.137.201

test201

[root@localhost conf]# elinks -source 192.168.137.201:8080

test201-8080

三、基于域名虛擬主機配置

1、添加域名的虛擬主機配置

[root@localhost conf.d]# vim virtualhost.conf      #編輯虛擬主機配置文件

[root@localhost conf.d]# cat virtualhost.conf      #內容如下, 紅色部分是在上面的基礎上添加的

NameVirtualHost 192.168.137.200:80 

<VirtualHost 192.168.137.200:80>

DocumentRoot "/var/www/test200"

ServerName    www.test200.com

</VirtualHost>

<VirtualHost 192.168.137.200:80>

DocumentRoot "/var/www/test200net"

ServerName    www.test200.net

</VirtualHost>

<VirtualHost 192.168.137.201:80>

DocumentRoot "/var/www/test201"

ServerName    www.test201.com

</VirtualHost>

<VirtualHost 192.168.137.201:8080>

DocumentRoot "/var/www/test2018080"

ServerName    www.test2018080.com

</VirtualHost>

[root@localhost conf.d]# !ser

service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]

[root@localhost conf.d]# cd /var/www            #切換目錄

[root@localhost www]# mkdir test200net          #創建目錄

[root@localhost www]# echo "test200net" >>./test200net/index.html  #創建主頁

2、測試

這里需要添加域名解析,沒有提供dns去解析,簡單的使用hosts文件區解析就可以了。

[root@localhost www]# vim /etc/hosts      編輯hosts文件, 添加兩行

[root@localhost www]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


192.168.137.200 www.test200.com

192.168.137.200 www.test200.net

接下來可以測試了

[root@localhost www]# elinks -source http://www.test200.com       #測試.com域

test200

[root@localhost www]# elinks -source http://www.test200.net       #測試.net域

test200net

英國服務器 俄羅斯主機
騰訊云代理

Copyright © 2003-2021 MFISP.COM. 國外vps服務器租用 夢飛云服務器租用 版權所有 ? 粵ICP備11019662號

主站蜘蛛池模板: 永胜县| 新建县| 扎兰屯市| 个旧市| 丹东市| 济阳县| 婺源县| 中卫市| 资兴市| 客服| 名山县| 卢龙县| 潼关县| 桃源县| 淅川县| 油尖旺区| 搜索| 西乡县| 沧州市| 阳高县| 客服| 白朗县| 息烽县| 泊头市| 交城县| 双辽市| 宁化县| 辽阳市| 五台县| 江达县| 儋州市| 磐安县| 东海县| 灯塔市| 永昌县| 台安县| 施甸县| 巩义市| 临泽县| 阳西县| 刚察县|