[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
235 # AllowOverride controls what directives may be placed in .htaccess files.
236 # It can be "All", "None", or any combination of the keywords:
237 # AllowOverride FileInfo AuthConfig Limit
238 #
★ AllowOverride all #修改为 AllowOverride all
240 #AllowOverride 表示是否去找.htacess文件作为配置文件
241 #
242 # Controls who can get stuff from this server.
2.在要添加认证的网页文件下创建 .htaccess 文件,并覆盖写入以下内容.
[root@localhost ~]# vim /usr/local/apache2/htdocs/.htaccess
authname "welcome to admin" #欢迎提示信息
authtype basic #认证类型
authuserfile /usr/local/apache2/htdocs/login.psd #认证文件存放位置
require valid-user #除认证用户其他用户不允许登陆
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
234 #
235 # AllowOverride controls what directives may be placed in .htaccess files.
236 # It can be "All", "None", or any combination of the keywords:
237 # AllowOverride FileInfo AuthConfig Limit
238 #
239 AllowOverride None
240
★ <requireall>
★ require all granted
★ require ip 192.168.1.10 #允许访问的IP地址
★ </requireall>
245
246 #
247 # Controls who can get stuff from this server.
248 #
249 #Require all granted#注释掉
250 </Directory>
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
235 # AllowOverride controls what directives may be placed in .htaccess files.
236 # It can be "All", "None", or any combination of the keywords:
237 # AllowOverride FileInfo AuthConfig Limit
238 #
239 AllowOverride None
240 <requireall>
241 require all granted
242 require not ip 192.168.1.10 #拒绝访问的IP地址
243 </requireall>
244 #
245 # Controls who can get stuff from this server.
246 #
247 #Require all granted#注释掉
248 </Directory>
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
496 # Note: The following must must be present to support
497 # starting without SSL on platforms with no /dev/random equivalent
498 # but a statically compiled-in mod_ssl.
499 #
500 <IfModule ssl_module>
501 SSLRandomSeed startup builtin
502 SSLRandomSeed connect builtin
503 </IfModule>
504
★ alias "/lyshark" "/usr/local/apache2/htdocs/a/b/c/d"#地址简化
#以上语句的含义:将访问路径由 http://IP地址/a/b/c/d 简化为 http://IP地址/lyshark
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
475
476 # Virtual hosts
★ Include conf/extra/httpd-vhosts.conf#取消本行注释,开启虚拟主机模块
478
479 # Local access to the Apache HTTP Server Manual
3.修改虚拟主机配置文件添加虚拟主机,在相应的区域中修改以下标★语句
[root@localhost ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
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 #
★ <VirtualHost 192.168.1.12:80>
24 ServerAdmin [email]webmaster@dummy-host.example.com[/email]
★ DocumentRoot "/usr/local/apache2/htdocs/vhost1"
26 ServerName dummy-host.example.com
27 ServerAlias [url]www.dummy-host.example.com[/url]
28 ErrorLog "logs/dummy-host.example.com-error_log"
29 CustomLog "logs/dummy-host.example.com-access_log" common
30 </VirtualHost>
31
★ <VirtualHost 192.168.1.13:80>
33 ServerAdmin [email]webmaster@dummy-host2.example.com[/email]
★ DocumentRoot "/usr/local/apache2/htdocs/vhost2"
35 ServerName dummy-host2.example.com
36 ErrorLog "logs/dummy-host2.example.com-error_log"
37 CustomLog "logs/dummy-host2.example.com-access_log" common
38 </VirtualHost>
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
475
476 # Virtual hosts
★ Include conf/extra/httpd-vhosts.conf#取消本行注释,开启虚拟主机模块
478
479 # Local access to the Apache HTTP Server Manual
2.修改虚拟主机配置文件添加虚拟主机,在相应的区域中修改以下标★语句
[root@localhost ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
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 #
★ <VirtualHost 192.168.1.12:80>
24 ServerAdmin [email]webmaster@dummy-host.example.com[/email]
★ DocumentRoot "/usr/local/apache2/htdocs/vhost1"
26 ServerName dummy-host.example.com
27 ServerAlias [url]www.dummy-host.example.com[/url]
28 ErrorLog "logs/dummy-host.example.com-error_log"
29 CustomLog "logs/dummy-host.example.com-access_log" common
30 </VirtualHost>
31
★ <VirtualHost 192.168.1.12:8080>
33 ServerAdmin [email]webmaster@dummy-host2.example.com[/email]
★ DocumentRoot "/usr/local/apache2/htdocs/vhost2"
35 ServerName dummy-host2.example.com
36 ErrorLog "logs/dummy-host2.example.com-error_log"
37 CustomLog "logs/dummy-host2.example.com-access_log" common
38 </VirtualHost>
3.修改Apache主配置文件,添加两个端口监听
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
48 # Change this to Listen on specific IP addresses as shown below to
49 # prevent Apache from glomming onto all bound IP addresses.
50 #
51 #Listen 12.34.56.78:80
★ Listen 80
★ Listen 8080
[root@localhost ~]# yum install -y bind bind-chroot
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager.
Package 32:bind-9.9.4-61.el7.x86_64 already installed and latest version
Package 32:bind-chroot-9.9.4-61.el7.x86_64 already installed and latest version
Nothing to do
2.配置DNS解析,这里我们简单配置即可,有关DNS详细例子请查看其他相关文章.
[root@localhost ~]# vim /etc/named.conf
12 options {
13 listen-on port 53 { any; };
14 listen-on-v6 port 53 { ::1; };
15 directory "/var/named";
16 dump-file "/var/named/data/cache_dump.db";
17 statistics-file "/var/named/data/named_stats.txt";
18 memstatistics-file "/var/named/data/named_mem_stats.txt";
19 allow-query { any; };
[root@localhost ~]# vim /etc/named.rfc1912.zones
43 zone "vhost1.com" IN {
44 type master;
45 file "vhost1.com.zone";
46 allow-update { none; };
47 };
48 zone "vhost2.com" IN {
49 type master;
50 file "vhost2.com.zone";
51 allow-update { none; };
52 };
3.拷贝配置文件,并修改成以下模样,并重启Bind
[root@localhost ~]# cp -a /var/named/named.localhost /var/named/vhost1.com.zone
[root@localhost ~]# cp -a /var/named/named.localhost /var/named/vhost2.com.zone
[root@localhost ~]# vim /var/named/vhost1.com.zone
$TTL 1D
@ IN SOA dns.vhost1.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.vhost1.com.
dns A 127.0.0.1
www A 192.168.1.10
[root@localhost ~]# vim /var/named/vhost2.com.zone
$TTL 1D
@ IN SOA dns.vhost2.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.vhost2.com.
dns A 127.0.0.1
www A 192.168.1.10
[root@localhost ~]# systemctl restart named
4.编辑Apache主配置文件,开启虚拟主机选项(取消注释),在相应的区域中取消以下标★注释
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
475
476 # Virtual hosts
★ Include conf/extra/httpd-vhosts.conf#取消本行注释,开启虚拟主机模块
478
479 # Local access to the Apache HTTP Server Manual
5.修改虚拟主机配置文件添加虚拟主机,在相应的区域中修改以下标★语句
[root@localhost ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
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 *:80>
24 ServerAdmin [email]webmaster@dummy-host.example.com[/email]
★ DocumentRoot "/usr/local/apache2/htdocs/vhost1"
★ ServerName [url]www.vhost1.com[/url]#vhost1.com解析到vhost1目录下
27 ServerAlias [url]www.dummy-host.example.com[/url]
28 ErrorLog "logs/dummy-host.example.com-error_log"
29 CustomLog "logs/dummy-host.example.com-access_log" common
30 </VirtualHost>
31
32 <VirtualHost *:80>
33 ServerAdmin [email]webmaster@dummy-host2.example.com[/email]
★ DocumentRoot "/usr/local/apache2/htdocs/vhost2"
★ ServerName [url]www.vhost2.com[/url]#vhost2.com解析到vhost2目录下
36 ErrorLog "logs/dummy-host2.example.com-error_log"
37 CustomLog "logs/dummy-host2.example.com-access_log" common
38 </VirtualHost>
[root@localhost ~]# yum install -y bind bind-chroot
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager.
Package 32:bind-9.9.4-61.el7.x86_64 already installed and latest version
Package 32:bind-chroot-9.9.4-61.el7.x86_64 already installed and latest version
Nothing to do
2.配置DNS解析,这里我们简单配置即可,有关DNS详细例子请查看其他相关文章.
[root@localhost ~]# vim /etc/named.conf
12 options {
13 listen-on port 53 { any; };
14 listen-on-v6 port 53 { ::1; };
15 directory "/var/named";
16 dump-file "/var/named/data/cache_dump.db";
17 statistics-file "/var/named/data/named_stats.txt";
18 memstatistics-file "/var/named/data/named_mem_stats.txt";
19 allow-query { any; };
[root@localhost ~]# vim /etc/named.rfc1912.zones
43 zone "vhost1.com" IN {
44 type master;
45 file "vhost1.com.zone";
46 allow-update { none; };
47 };
48 zone "vhost2.com" IN {
49 type master;
50 file "vhost2.com.zone";
51 allow-update { none; };
52 };
3.拷贝配置文件,并修改成以下模样,并重启Bind
[root@localhost ~]# cp -a /var/named/named.localhost /var/named/vhost1.com.zone
[root@localhost ~]# cp -a /var/named/named.localhost /var/named/vhost2.com.zone
[root@localhost ~]# vim /var/named/vhost1.com.zone
$TTL 1D
@ IN SOA dns.vhost1.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.vhost1.com.
dns A 127.0.0.1
www A 192.168.1.10
[root@localhost ~]# vim /var/named/vhost2.com.zone
$TTL 1D
@ IN SOA dns.vhost2.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.vhost2.com.
dns A 127.0.0.1
www A 192.168.1.10
[root@localhost ~]# systemctl restart named
[root@localhost ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
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 *:80>
★ DocumentRoot "/usr/local/apache2/htdocs/vhost1"#vhost1网页存放位置
★ ServerName [url]www.vhost1.com[/url]#域名vhost1.com
26 </VirtualHost>
27
★ <Directory "/usr/local/apache2/htdocs/vhost1">#vhost1页面的路径
★ Options indexes followsymlinks
★ Allowoverride all
★ Require all granted
★ </Directory>
33
34 <VirtualHost *:80>
★ DocumentRoot "/usr/local/apache2/htdocs/vhost2"#vhost2网页存放位置
★ ServerName [url]www.vhost2.com[/url]#域名vhost2.com
37 </VirtualHost>
[root@localhost ~]# cp -a servernew.crt /usr/local/apache2/conf/server.crt#将证书复制到conf目录下
[root@localhost ~]# cp -a server.key /usr/local/apache2/conf/server.key#私钥也要放入conf目录下
5.编辑主配置文件开启相应功能(取消注释)
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
133 LoadModule ssl_module modules/mod_ssl.so#开启ssl功能(约在133行)
493 # Secure (SSL/TLS) connections
494 Include conf/extra/httpd-ssl.conf#开启ssl模板,搜索SSLRandomSeed(约在494行)
6.配置SSL模板文件
[root@localhost ~]# vim /usr/local/apache2/conf/extra/httpd-ssl.conf
88 # Inter-Process Session Cache:
89 # Configure the SSL Session Cache: First the mechanism
90 # to use and second the expiring timeout (in seconds).
91 #SSLSessionCache "dbm:/usr/local/apache2/logs/ssl_scache"#注释掉
92 #SSLSessionCache "shmcb:/usr/local/apache2/logs/ssl_scache(512000)"#注释掉
93 #SSLSessionCacheTimeout 300#注释掉