1. 程式人生 > >​基於域名虛擬主機及主站遷移

​基於域名虛擬主機及主站遷移

​基於域名虛擬主機及主站遷移

1.配置BIND支持多域名解析:在實際工作中需要申請多個域名,並做好解析。

登錄到192.168.100.100(已經提供了linuxfan.cn的解析)

[root@ns ~]# vim /var/named/chroot/etc/named.conf ##在該文件末尾添加如下內容

zone "gxfc.com" IN {
        type master;
        file "gxfc.com.zone";
};

:wq


[root@ns ~]# vim /var/named/chroot/var/named/gxfc.com.zone ##新建區域數據文件

$TTL 86400
@       IN      SOA     gxfc.com.      root.gxfc.com. (
                20170630
                1H
                2M
                3W
                1D
)
@       IN      NS      ns.gxfc.com.
@       IN      A       192.168.100.100
ns      IN      A       192.168.100.100
www     IN      A       192.168.100.150

:wq

[root@ns ~]# /etc/init.d/named restart ##重啟服務

[root@ns ~]# nslookup

> server 192.168.100.100

Default server: 192.168.100.100

Address: 192.168.100.100#53

> www.gxfc.com

Server: 192.168.100.100

Address: 192.168.100.100#53


Name: www.gxfc.com ##解析成功

Address: 192.168.100.150

> www.linuxyy.cn

Server: 192.168.100.100

Address: 192.168.100.100#53


Name: www.linuxyy.cn

Address: 192.168.100.150

> exit


[root@ns ~]#


2.配置基於域名的虛擬主機:登錄到192.168.100.150上

1)設置虛擬主機站點的網頁根目錄:(測試數據)

[root@www ~]# cd /usr/local/httpd/htdocs/

[root@www ~]# mkdir linuxyy

[root@www ~]# mkdir gxfc

[root@www ~]# echo "www.linuxyy.cn" >>linuxyy/index.html

[root@www ~]# echo "www.gxfc.com" >>gxfc/index.html

2)修改虛擬主機配置文件:

[root@www ~]# vim /usr/local/httpd/conf/httpd.conf

387 Include conf/extra/httpd-vhosts.conf ##去掉該行的註釋

388

:set nu 388,0-1 88%

:wq


[root@www ~]# cd /usr/local/httpd/conf/extra/ ;ls

[root@www extra]# cp httpd-vhosts.conf httpd-vhosts.conf.bak ##備份配置文件,養成好習慣

[root@www ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf ##修改配置文件如下

NameVirtualHost 192.168.100.150:80

<VirtualHost 192.168.100.150:80>

ServerAdmin [email protected]

DocumentRoot "/usr/local/httpd/htdocs/linuxyy"

ServerName www.linuxyy.cn

ErrorLog "logs/www.linuxyy.cn-error_log"

CustomLog "logs/www.linuxyy.cn-access_log" combined

</Virtualhost>

<VirtualHost 192.168.100.150:80>

ServerAdmin [email protected]

DocumentRoot "/usr/local/httpd/htdocs/gxfc/"

ServerName www.gxfc.com

ErrorLog "logs/www.gxfc.com-error_log"

CustomLog "logs/www.gxfc.com-access_log" combined

</VirtualHost>

:wq

3)測試:虛擬主機(登錄到192.168.100.100)

[root@ns ~]# vim /etc/resolv.conf ##編輯配置文件確認如下行

[root@ns ~]# cat /etc/resolv.conf

; generated by /sbin/dhclient-script

nameserver 192.168.100.100 ##添加該行

nameserver 192.168.1.1

[root@ns ~]# elinks --dump www.linuxyy.cn ##訪問成功

www.linuxfan.cn

[root@ns ~]# elinks --dump www.gxfc.com ##訪問成功

www.sggfu.com

windows主機用瀏覽器訪問:

http://www.linuxyy.cn

http://www.gxfc.com

http://www.linuxyy.cn/aws.html ##無法訪問


3.主站遷移:

目前虛擬主機測試已經成功,問題在於老站www.linuxyy.cn中的web依然需要提供,下面將完成主站遷移,實現舊資源依然能訪問:

1)移動老站資源:

[root@www ~]# tree /usr/local/httpd/htdocs/ ##樹形結構查看網頁根目錄下的內容

/usr/local/httpd/htdocs/

├── aws.html

├── index.html

├── linuxyy

│ └── index.html

└── gxfc

└── index.html


2 directories, 4 files

[root@www ~]# cd /usr/local/httpd/htdocs/

[root@www htdocs]# ls

aws.html index.html linuxyy gxfc

[root@www htdocs]# mv aws.html index.html linuxyy/ ##將所有老站的內容移動到新站目錄下

mv:是否覆蓋"linuxyy/index.html"? y

[root@www htdocs]#


2)修改配置文件:

[root@www ~]# vim /usr/local/httpd/conf/httpd.conf ##註釋掉主配置文件中關於awstats的配置

413 #Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"

414 #Alias /awstatscss "/usr/local/awstats/wwwroot/css/"

415 #Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"

416 #ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"

417 #

418 ##

419 ## This is to permit URL access to scripts/files in AWStats directory.

420 ##

421 #<Directory "/usr/local/awstats/wwwroot">

422 # Options None

423 # AllowOverride None

424 # Order allow,deny

425 # Allow from 192.168.100.1

426 # AuthType Basic

427 # AuthName "Log analysis system"

428 # AuthBasicProvider file

429 # AuthUserFile /usr/local/httpd/conf/htpasswd

430 # AuthGroupFile /usr/local/httpd/conf/htgroups

431 # Require group mygroup

432 #</Directory>

433 #

:413,$ s/^/#/g

:wq

[root@www ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf ##修虛擬主機配置文件,將主配置文件中註釋掉的配置文件項復制到第一個虛擬配置區域內


Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"

Alias /awstatscss "/usr/local/awstats/wwwroot/css/"

Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"

ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"


<Directory "/usr/local/awstats/wwwroot">

Options None

AllowOverride None

Order allow,deny

Allow from 192.168.100.1

AuthType Basic

AuthName "Log analysis system"

AuthBasicProvider file

AuthUserFile /usr/local/httpd/conf/htpasswd

AuthGroupFile /usr/local/httpd/conf/htgroups

Require group mygroup

</Directory>

:wq

[root@www ~]# /etc/init.d/httpd restart ##重啟服務

httpd is restart complete.

[root@www ~]#

[root@www ~]# vim /etc/awstats/awstats.www.linuxyy.cn.conf ##修改第50行如下

LogFile="/usr/local/httpd/logs/www.linuxyy.cn-access_log"

:wq

[root@www ~]# /usr/local/awstats/tools/awstats_updateall.pl now


訪問測試:

192.168.100.100上:測試成功

[root@ns ~]# elinks --dump www.linuxyy.cn

www.linuxyy.cn


[1]日誌分析平臺


References


Visible links

1. http://www.linuxyy.cn/aws.html

[root@ns ~]#

windows上使用IE訪問測試:點擊後成功訪問。

http://www.linuxyy.cn/





附加內容:

[root@www linuxyy]# cat index.html

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>linuxyy</title>

</head>

<body>

<h1>www.linuxyy.cn</h1>

<a href="aws.html">日誌分析平臺</a>

</body>

</html>

[root@www linuxyy]# cat aws.html

<html>

<head>

<meta http-equiv="refresh" content="0; url=http://www.linuxyy.cn/awstats/awstats.pl?config=www.linuxyy.cn" />

</head>

<body></body>

</html>

[root@www linuxyy]#


本文出自 “11628205” 博客,請務必保留此出處http://11638205.blog.51cto.com/11628205/1981717

​基於域名虛擬主機及主站遷移