Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
base | 4.1 kB 00:00
Resolving Dependencies
……………
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Tue 2015-05-19 18:00:39 CST; 12s ago
Main PID: 5896 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─5896 /usr/sbin/httpd -DFOREGROUND
├─5897 /usr/sbin/httpd -DFOREGROUND
├─5898 /usr/sbin/httpd -DFOREGROUND
├─5899 /usr/sbin/httpd -DFOREGROUND
├─5900 /usr/sbin/httpd -DFOREGROUND
└─5901 /usr/sbin/httpd -DFOREGROUND
May 19 18:00:39 server30.example.com systemd[1]: Starting The Apache HTTP Se....
May 19 18:00:39 server30.example.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
total 24
-rw-r--r--. 1 root root 2893 Mar 20 2014 autoindex.conf
-rw-r--r--. 1 root root 1511 May 19 19:29 httpd-vhosts.conf
-rw-r--r--. 1 root root 295 Mar 20 2014 manual.conf
-rw-r--r--. 1 root root 366 Mar 20 2014 README
-rw-r--r--. 1 root root 1252 Mar 20 2014 userdir.conf
//个人主页文件
-rw-r--r--. 1 root root 516 Mar 20 2014 welcome.conf
4.3.Web与DNS的关系
我们知道,访问网页是通过URL即http://www.baidu.com的方式实现的,通过域名来解析IP地址,实现网页的访问,而这个过程是需要DNS(Domain Name Server)来实现的。否则,我们访问网页只能通过IP的形式来实现,对于专业人士来说,可能不算什么,但是对于非专业人士来说,通过IP访问网页就是件很难的事了。所以,本部分内容我们主要介绍怎样通过DNS来实现域名解析IP,实现网页访问。
DNS的安装,启动及配主配置文件的设置详见【第四章:DNS】,本部分主要介绍如何配置解析文件来实现域名的解析。
假设现在服务器端server30.example.com(172.16.30.130)有网站server30.example.com(IP:172.16.30.130),www.example.com(IP:172.16.30.130),那么怎样实现解析呢?如下:
[root@server30 ~]# vim /etc/unbound/local.d/example.conf
local-zone: "example.com." static
local-data: "example.com. IN SOA ns.example.com. root 1 1D 1H 1W 1H"
local-data: "ns.example.com. IN A 172.16.30.130"
local-data: "server30.example.com. IN A 172.16.30.130"
local-data: "www.example.com. IN A 172.16.30.130"
local-data-ptr: "172.16.30.130 ns.example.com."
local-data-ptr: "172.16.30.130 server30.example.com."
local-data-ptr: "172.16.30.130 www.example.com."
配置完解析文件,可以使用unbound-check检查配置,然后重启服务
[root@freeit ~]# unbound-checkconf
unbound-checkconf: no errors in /etc/unbound/unbound.conf
[root@freeit ~]# systemctl restart unbound
服务器端配置完DNS之后,就可以在客户端指定DNS Server并进行验证
[root@desktop30 ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 172.16.30.130
[root@server30 httpd]# vim /etc/httpd/conf.d/userdir.conf
1 #
2 # UserDir: The name of the directory that is appended onto a user's home
3 # directory if a ~user request is received.
4 #
5 # The path to the end user account 'public_html' directory must be
6 # accessible to the webserver userid. This usually means that ~userid 7 # must have permissions of 711, ~userid/public_html must have permissions 8 # of 755, and documents contained therein must be world-readable.
9 # Otherwise, the client will only receive a "403 Forbidden" message.
10 #
11 <IfModule mod_userdir.c>
12 #
13 # UserDir is disabled by default since it can confirm the presence
14 # of a username on the system (depending on home directory
15 # permissions).
16 #
17 UserDir disabled
18
19 #
20 # To enable requests to /~user/ to serve the user's public_html
21 # directory, remove the "UserDir disabled" line above, and uncomment
22 # the following line instead:
23 #
24 #UserDir public_html
25 </IfModule>
26
27 #
28 # Control access to UserDir directories. The following is an example
29 # for a site where these directories are restricted to read-only.
30 #
31 <Directory "/home/*/public_html">
32 AllowOverride FileInfo AuthConfig Limit Indexes
33 Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
34 Require method GET POST OPTIONS
35 </Directory>
36
total 24
-rw-r--r--. 1 root root 2893 Mar 20 2014 autoindex.conf -rw-r--r--. 1 root root 1511 Mar 20 2014 httpd-vhosts.conf
-rw-r--r--. 1 root root 295 Mar 20 2014 manual.conf
-rw-r--r--. 1 root root 366 Mar 20 2014 README
-rw-r--r--. 1 root root 1297 May 19 20:37 userdir.conf
-rw-r--r--. 1 root root 516 Mar 20 2014 welcome.conf
打开文件查看
[root@server30 conf.d]# vim httpd-vhosts.conf
5 # If you want to maintain multiple domains/hostnames on your
6 # machine you can setup VirtualHost containers for them. Most configurations
7 # use only name-based virtual hosts so the server doesn't need to worry abou
t
8 # IP addresses. This is indicated by the asterisks in the directives below.
9 #
10 # Please see the documentation at
11 # <URL:http://httpd.apache.org/docs/2.4/vhosts/>
12 # for further details before you try to setup virtual hosts.
13 #
14 # You may use the command line option '-S' to verify your virtual host
15 # configuration.
16
17 #
18 # VirtualHost example:
19 # Almost any Apache directive may go into a VirtualHost container.
20 # The first VirtualHost section is used for all requests that do not
21 # match a ServerName or ServerAlias in any <VirtualHost> block.
22 #
23 <VirtualHost *:@@Port@@>
24 ServerAdmin webmaster@dummy-host.example.com
25 DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
26 ServerName dummy-host.example.com
27 ServerAlias www.dummy-host.example.com
28 ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
29 CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
30 </VirtualHost>
31
32 <VirtualHost *:@@Port@@>
33 ServerAdmin webmaster@dummy-host2.example.com
34 DocumentRoot "@@ServerRoot@@/docs/dummy-host2.example.com"
35 ServerName dummy-host2.example.com
36 ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
37 CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
38 </VirtualHost>
有效行为38行,我们可以复制23到28行内容设置虚拟主机,复制后直接进行修改,如下,为修改后的内容
40 <VirtualHost 172.16.30.130:80> ①
41 ServerAdmin root@server30.example.com ②
42 DocumentRoot "/var/www/html" ③
43 ServerName server30.example.com ④
44 ErrorLog "/var/log/httpd/server30.example.com-error_log" ⑤
45 CustomLog "/var/log/httpd/server30.example.com-access_log" common ⑥
46 </VirtualHost>
47
48 <VirtualHost 172.16.30.130:80>
49 ServerAdmin root@www.example.com
50 DocumentRoot "/var/www/virtual"
51 ServerName www.example.com
52 ErrorLog "/var/log/httpd/www.example.com-error_log"
53 CustomLog "/var/log/httpd/www.example.com-access_log" common
54 </VirtualHost>
[root@server30 ~]# vim /etc/httpd/conf.d/httpd-vhosts.conf
6 # machine you can setup VirtualHost containers for them. Most configurations
8 # IP addresses. This is indicated by the asterisks in the directives below.
9 #
10 # Please see the documentation at
11 # <URL:http://httpd.apache.org/docs/2.4/vhosts/>
12 # for further details before you try to setup virtual hosts.
13 #
14 # You may use the command line option '-S' to verify your virtual host
15 # configuration.
16
17 #
18 # VirtualHost example:
19 # Almost any Apache directive may go into a VirtualHost container.
20 # The first VirtualHost section is used for all requests that do not
21 # match a ServerName or ServerAlias in any <VirtualHost> block.
22 #
23 <VirtualHost *:@@Port@@>
24 ServerAdmin webmaster@dummy-host.example.com
25 DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
26 ServerName dummy-host.example.com
27 ServerAlias www.dummy-host.example.com
28 ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
29 CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
30 </VirtualHost>
31
32 <VirtualHost *:@@Port@@>
33 ServerAdmin webmaster@dummy-host2.example.com
34 DocumentRoot "@@ServerRoot@@/docs/dummy-host2.example.com"
35 ServerName dummy-host2.example.com
36 ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
37 CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
38 </VirtualHost>
39
40 <VirtualHost 172.16.30.130:80>
41 ServerAdmin root@server30.example.com
42 DocumentRoot "/var/www/html"
43 <Directory "/var/www/html/data">
44 Options Indexes
45 Order deny,allow 46 deny from all 47 allow from 172.16.30.130
48 </Directory>
49 ServerName server30.example.com
50 ErrorLog "/var/log/httpd/server30.example.com-error_log"
51 CustomLog "/var/log/httpd/server30.example.com-access_log" common
52 </VirtualHost>
53
54 <VirtualHost 172.16.30.130:80>
55 ServerAdmin root@www.example.com
56 DocumentRoot "/var/www/virtual"
57 ServerName www.example.com
[root@server30 ~]# vim /etc/httpd/conf.d/httpd-vhosts.conf
8 # IP addresses. This is indicated by the asterisks in the directives below.
9 #
10 # Please see the documentation at
11 # <URL:http://httpd.apache.org/docs/2.4/vhosts/>
12 # for further details before you try to setup virtual hosts.
13 #
14 # You may use the command line option '-S' to verify your virtual host
15 # configuration.
16
17 #
18 # VirtualHost example:
19 # Almost any Apache directive may go into a VirtualHost container.
20 # The first VirtualHost section is used for all requests that do not
21 # match a ServerName or ServerAlias in any <VirtualHost> block.
22 #
23 <VirtualHost *:@@Port@@>
24 ServerAdmin webmaster@dummy-host.example.com
25 DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
26 ServerName dummy-host.example.com
27 ServerAlias www.dummy-host.example.com
28 ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
29 CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
30 </VirtualHost>
31
32 <VirtualHost *:@@Port@@>
33 ServerAdmin webmaster@dummy-host2.example.com
34 DocumentRoot "@@ServerRoot@@/docs/dummy-host2.example.com"
35 ServerName dummy-host2.example.com
36 ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
37 CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
38 </VirtualHost>
39
40 <VirtualHost 172.16.30.130:80>
41 ServerAdmin root@server30.example.com
42 DocumentRoot "/var/www/html"
43 <Directory "/var/www/html/data">
44 Options Indexes
45 Require ip 172.16.30.30
46 </Directory>
47 ServerName server30.example.com
48 ErrorLog "/var/log/httpd/server30.example.com-error_log"
49 CustomLog "/var/log/httpd/server30.example.com-access_log" common
50 </VirtualHost>
51
52 <VirtualHost 172.16.30.130:80>
53 ServerAdmin root@www.example.com
54 DocumentRoot "/var/www/virtual"
55 ServerName www.example.com
56 ErrorLog "/var/log/httpd/www.example.com-error_log"
57 CustomLog "/var/log/httpd/www.example.com-access_log" common
58 </VirtualHost>
[root@server30 ~]# vim /etc/httpd/conf.d/httpd-vhosts.conf
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
19 # Almost any Apache directive may go into a VirtualHost container.
20 # The first VirtualHost section is used for all requests that do not
21 # match a ServerName or ServerAlias in any <VirtualHost> block.
22 #
23 <VirtualHost *:@@Port@@>
24 ServerAdmin webmaster@dummy-host.example.com
25 DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
26 ServerName dummy-host.example.com
27 ServerAlias www.dummy-host.example.com
28 ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
29 CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
30 </VirtualHost>
31
32 <VirtualHost *:@@Port@@>
33 ServerAdmin webmaster@dummy-host2.example.com
34 DocumentRoot "@@ServerRoot@@/docs/dummy-host2.example.com"
35 ServerName dummy-host2.example.com
36 ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
37 CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
38 </VirtualHost>
39
40 <VirtualHost 172.16.30.130:80>
41 ServerAdmin root@server30.example.com
42 DocumentRoot "/var/www/html"
43 <Directory "/var/www/html/data">
44 Options Indexes
45 Require all denied
46 </Directory>
47 ServerName server30.example.com
48 ErrorLog "/var/log/httpd/server30.example.com-error_log"
49 CustomLog "/var/log/httpd/server30.example.com-access_log" common
50 </VirtualHost>
51
52 <VirtualHost 172.16.30.130:80>
53 ServerAdmin root@www.example.com
54 DocumentRoot "/var/www/virtual"
55 ServerName www.example.com
56 ErrorLog "/var/log/httpd/www.example.com-error_log"
57 CustomLog "/var/log/httpd/www.example.com-access_log" common
58 </VirtualHost>
[root@server30 ~]# vim /etc/httpd/conf.d/httpd-vhosts.conf
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
19 # Almost any Apache directive may go into a VirtualHost container.
20 # The first VirtualHost section is used for all requests that do not
21 # match a ServerName or ServerAlias in any <VirtualHost> block.
22 #
23 <VirtualHost *:@@Port@@>
24 ServerAdmin webmaster@dummy-host.example.com
25 DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
26 ServerName dummy-host.example.com
27 ServerAlias www.dummy-host.example.com
28 ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
29 CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
30 </VirtualHost>
31
32 <VirtualHost *:@@Port@@>
33 ServerAdmin webmaster@dummy-host2.example.com
34 DocumentRoot "@@ServerRoot@@/docs/dummy-host2.example.com"
35 ServerName dummy-host2.example.com
36 ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
37 CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
38 </VirtualHost>
39
40 <VirtualHost 172.16.30.130:80>
41 ServerAdmin root@server30.example.com
42 DocumentRoot "/var/www/html"
43 <Directory "/var/www/html/data">
44 Options Indexes
45 AuthName Test ① 46 AuthType basic ② 47 AuthUserFile /etc/httpd/.htpasswd ③ 48 Require valid-user ④
49 </Directory>
50 ServerName server30.example.com
51 ErrorLog "/var/log/httpd/server30.example.com-error_log"
52 CustomLog "/var/log/httpd/server30.example.com-access_log" common
53 </VirtualHost>
54
55 <VirtualHost 172.16.30.130:80>
56 ServerAdmin root@www.example.com
57 DocumentRoot "/var/www/virtual"
58 ServerName www.example.com
59 ErrorLog "/var/log/httpd/www.example.com-error_log"
60 CustomLog "/var/log/httpd/www.example.com-access_log" common
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
base | 4.1 kB 00:00
Resolving Dependencies
………………..
配置/etc/httpd/conf.d/ssl.conf文件
[root@server30 ~]# cd /etc/httpd/conf.d/
[root@server30 conf.d]# ll
total 36
-rw-r--r--. 1 root root 2893 Mar 20 2014 autoindex.conf
-rw-r--r--. 1 root root 2251 May 20 10:36 httpd-vhosts.conf
-rw-r--r--. 1 root root 295 Mar 20 2014 manual.conf
-rw-r--r--. 1 root root 366 Mar 20 2014 README -rw-r--r--. 1 root root 9426 Mar 20 2014 ssl.conf
-rw-r--r--. 1 root root 1297 May 19 20:37 userdir.conf
-rw-r--r--. 1 root root 516 Mar 20 2014 welcome.conf
[root@server30 conf.d]# vim ssl.conf
……………………….. 100 SSLCertificateFile /etc/pki/tls/certs/localhost.crt
101
102 # Server Private Key:
103 # If the key is not combined with the certificate, use this
104 # directive to point at the key file. Keep in mind that if
105 # you've both a RSA and a DSA private key you can configure
106 # both in parallel (to also allow the use of DSA ciphers, etc.) 107 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
108
109 # Server Certificate Chain:
110 # Point SSLCertificateChainFile at a file containing the
111 # concatenation of PEM encoded CA certificates which form the
112 # certificate chain for the server certificate. Alternatively
113 # the referenced file can be the same as SSLCertificateFile
114 # when the CA certificates are directly appended to the server
115 # certificate for convinience.
116 #SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
117
118 # Certificate Authority (CA):
119 # Set the CA certificate verification path where to find CA
120 # certificates for client authentication or alternatively one
121 # huge file containing all of them (file must be PEM encoded) 122 #SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
……….
………………………..
100 #SSLCertificateFile /etc/pki/tls/certs/localhost.crt 101 SSLCertificateFile /etc/pki/tls/certs/server30.crt
102
103 # Server Private Key:
104 # If the key is not combined with the certificate, use this
105 # directive to point at the key file. Keep in mind that if
106 # you've both a RSA and a DSA private key you can configure
107 # both in parallel (to also allow the use of DSA ciphers, etc.)
108 #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key 109 SSLCertificateKeyFile /etc/pki/tls/private/server30.key
110
111 # Server Certificate Chain:
112 # Point SSLCertificateChainFile at a file containing the
113 # concatenation of PEM encoded CA certificates which form the
114 # certificate chain for the server certificate. Alternatively
115 # the referenced file can be the same as SSLCertificateFile
116 # when the CA certificates are directly appended to the server
117 # certificate for convinience.
118 SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
119
120 # Certificate Authority (CA):
121 # Set the CA certificate verification path where to find CA
122 # certificates for client authentication or alternatively one
123 # huge file containing all of them (file must be PEM encoded)
124 #SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt 125 SSLCACertificateFile /etc/pki/tls/certs/group30.crt
……………
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
………………….