本内容涉及到的知识:安装HTTP服务、安装DNS服务(用于域名访问)、配置HTTP服务、配置虚拟目录。
一、安装HTTP服务、DNS服务。
(1)使用yum安装HTTP服务。
[root@localhost thrfur] yum install httpd -y
(2)使用yum安装DNS服务。
[root@localhost thrfur] yum install bind bind-utils -y
二、配置HTTP服务。
(1)查看本机地址,使用 ifconfig
命令。其中 192.168.34.131 即为本机地址。
[root@localhost thrfur]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.34.131 netmask 255.255.255.0 broadcast 192.168.34.255
inet6 fe80::351a:e68a:556d:bebd prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:38:4b:2a txqueuelen 1000 (Ethernet)
RX packets 36 bytes 3866 (3.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 246 bytes 23773 (23.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
(2)备份 /etc/httpd/conf/httpd.conf
文件。
[root@localhost thrfur]# cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
(3)使用vim编辑器编辑 httpd.conf 文件:vim /etc/httpd/conf/httpd.conf
,在末尾插入如下内容。
<VirtualHost 192.168.34.131:80>
DocumentRoot /var/www/html //根目录
Servername www.thrfur.com //域名
DirectoryIndex index.html //默认文件
ServerAdmin admin@thrfur.com //管理员
AddDefaultCharset UTF-8 //编码方式
</VirtualHost>
(4)在 /var/www/html
内新建 [hl]index.html[/hl] 文件。
[root@localhost thrfur]# touch /var/www/html/index.html
(5)使用vim编辑器编辑index.html文件:vim /var/www/html/index.html
,添加如下内容。
<html>
<head><title>thrfur</title></head>
<body>Welcome to thrfur WebSite.</body>
</html>
三、配置DNS服务。
(1)备份DNS配置文件。
[root@localhost thrfur]# cp -p /etc/named.conf /etc/named.conf.bak
(2)使用vim编辑器编辑named.conf文件:vim /etc/named.conf,修改两处地方。
options {
listen-on port 53 { any; }; <---修改为any
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; }; <---修改为any
(3)编辑区域文件:vim /etc/named.rfc1912.zones
,加入如下内容。
zone "thrfur.com" IN {
type master;
file "named.thrfur.com";
allow-update { none; };
};
zone "34.168.192.in-addr.arpa" IN {
type master;
file "named.192.168.34";
allow-update { none; };
};
(4)复制模板为正反解析文件。
[root@localhost thrfur]# cp -p /var/named/named.localhost /var/named/named.thrfur.com
[root@localhost thrfur]# cp -p /var/named/named.localhost /var/named/named.192.168.34
(5)编辑named.thrfur.com文件:vim /var/named/named.thrfur.com
,加入如下内容。
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
www A 192.168.34.131 <--加入这一行
(6)编辑named.192.168.34文件:vim /var/named/named.192.168.34
,加入如下内容。
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
131 IN PTR www.thrfur.com. <--加入这一行(末尾有个点)
(7)授权正反解析文件。
[root@localhost thrfur]# chown :named /var/named/named.thrfur.com
[root@localhost thrfur]# chown :named /var/named/named.192.168.34
(8)修改DNS为本机IP:vim /etc/resolv.conf
,修改为如下内容。
# Generated by NetworkManager
nameserver 192.168.34.131
(9)关闭防火墙,关闭selinux。
[root@localhost thrfur]# systemctl stop firewalld
[root@localhost thrfur]# setenforce 0
(10)开启HTTP、DNS服务。
[root@localhost thrfur]# systemctl start httpd
[root@localhost thrfur]# systemctl start named
(11)正反解析配置完成。
四、配置虚拟目录。
(1)创建目录 /var/www/thrfur,并创建index.html文件。
[root@localhost thrfur]# mkdir /var/www/thrfur
[root@localhost thrfur]# touch /var/www/thrfur/index.html
(2)编辑httpd.conf文件:vim /etc/httpd/conf/httpd.conf
,加入如下内容。
alias /blog "/var/www/thrfur" //定义虚拟目录,访问/blog其实访问的是/var/www/html目录
<Directory "/var/www/thrfur">
Options Indexes MultiViews FollowSymLinks //固定格式
AllowOverride None //固定格式
Order allow,deny //匹配顺序为先允许,后拒绝
Allow from all //允许所有人访问
Require all granted //给这个目录授权
</Directory>
(3)向/var/www/thrfur/index.html文件写入如下内容。
<html>
<head><title>thrfur-2</title></head>
<body>This is thrfur virtual directory</body>
</html>
(4)重启HTTP、DNS服务,关闭防火墙和selinux。
[root@localhost thrfur]# systemctl restart httpd
[root@localhost thrfur]# systemctl restart named
[root@localhost thrfur]# systemctl stop firewalld
[root@localhost thrfur]# setenforce 0
(5)虚拟目录配置完成。