<!-- 2018-01-02 -->
Apache相关文件
1.目录别名实验
/usr/local/apache2/htdocs/目录/文件 -- 访问:192.168.0.104
/usr/local/apache2/shop/ -- 访问:192.168.0.104/shop/
用途:目录扩容 增加服务器
1).建立目录
mkdir /usr/local/apache2/shop/
2).修改配置文件
①修改主配置文件
vim /usr/local/apache2/conf(etc)/httpd.conf
454 Include etc//extra/httpd-autoindex.conf -- 引入子配置文件
②修改子配置文件
vim /usr/local/apache2/etc/extra/httpd-autoindex.conf
21 Alias /icons/ "/usr/local/apache2//icons/" -- apache默认存放图片的位置
24 Options Indexes MultiViews -- MultiViews 多语言支持功能,国内开发可以不用设置MultiViews
29 Alias /shop/ "/usr/local/apache2/shop/"
30
31 <Directory "/usr/local/apache2/shop">
32 Options Indexes MultiViews
33 AllowOverride None
34 Require all granted
35 </Directory>
3).测试
192.168.0.104/shop/
2.虚拟主机实验
在一台服务器上,解析运行多个网站的技术;节约企业成本
访问网站的过程: 域名A --> IP --> 服务器 --> /目录A/index.html
域名B --> IP --> 服务器 --> /目录B/index.html
实验要求:在服务器上IP 192.168.0.104解析运行 www.sina.com www.souhu.com两个网站
1).域名解析 -- 使用文件解析
C:\Windows\System32\drivers\etc\hosts
里面内容默认都是注释掉的,添加:
192.168.0.104 www.sina.com
192.168.0.104 www.souhu.com
2).网站目录规划
mkdir -p /share/sina/
mkdir /share/sohu/
3).修改配置文件
①修改主配置文件
vim /usr/local/apache2/etc/httpd.conf
190 ServerName www.example.com:80
466 Include etc//extra/httpd-vhosts.conf
②修改子配置文件
vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
23 <Directory "/share/sina/"> -- sina目录权限
24 Options Indexes
25 AllowOverride None
26 Require all grandted
27 </Directory>
28
29 <Directory "/share/sohu/"> -- sohu目录权限
30 Options Indexes
31 AllowOverride None
32 Require all grandted
33 </Directory>
34
35 <VirtualHost 192.168.0.104> -- sina虚拟主机
36 ServerAdmin webmaster@sina.com
37 DocumentRoot "/share/sina/"
38 ServerName www.sina.com
39 # ServerAlias www.dummy-host.example.com
40 ErrorLog "logs/sina-error_log"
41 CustomLog "logs/sina-access_log" common
42 </VirtualHost>
43
44 <VirtualHost 192.168.0.104> -- sohu虚拟主机
45 ServerAdmin webmaster@sohu.com
46 DocumentRoot "/share/sohu/"
47 ServerName www.sohu.com
48 ErrorLog "logs/sohu-error_log"
49 CustomLog "logs/sohu-access_log" common
50 </VirtualHost>
4).重启服务
sto,sta
测试 www.sina.com www.sohu.com
3.rewrite重写重定向
域名跳转 www.sina.com 跳转到 www.sohu.com
1).修改配置文件
①修改主配置文件
vim /usr/local/apache2/etc/httpd.conf
147 LoadModule rewrite_module modules/mod_rewrite.so
②修改子配置文件
vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
29 <Directory "/share/sohu/">
30 Options Indexes FollowSymLinks -- 跳转、链接
31 AllowOverride all -- 打开.htaccess文件权限,进行跳转时候的判断
32 Require all granted
33 </Directory>
2).建立文件权限.htaccess
vim /share/sina/.htaccess
1 RewriteEngine on -- 重定向引擎功能,on开启,off关闭
2 RewriteCond %{HTTP_HOST} www.sina.com -- 进行判断(赋值),将www.sina.com赋值给地址栏
3 RewriteRule .* http://www.sohu.com -- 重写规则,“.*”代表匹配符合1.2条件后的所有
3).测试:sto sta www.sina.com --> www.sohu.com 301永久重定向
4.网页文件的跳转
要求:假如系统没有index5.html文件,访问www.sina.com/index5.html,会跳转到一个动态的index.php文件的位置,并且
显示文件的内容,对文件进行解析
1).修改权限文件..htaccess
vim /share/sina/.htaccess
1 RewriteEngine on
2 RewriteRule index(\d+).html index.php?id=$1 -- 当我们输入index数字.html时,就跳转到index.php文件
2).建立index.php文件
vim /share/sina/index.php
<?php
echo "Hello rewrite"
?>
3).测试
sto sta www.sina.com/index5.html
实现了静态文件向动态文件的跳转,伪静态:保护网站的安全 提升网站性能
Apache相关文件
1.目录别名实验
/usr/local/apache2/htdocs/目录/文件 -- 访问:192.168.0.104
/usr/local/apache2/shop/ -- 访问:192.168.0.104/shop/
用途:目录扩容 增加服务器
1).建立目录
mkdir /usr/local/apache2/shop/
2).修改配置文件
①修改主配置文件
vim /usr/local/apache2/conf(etc)/httpd.conf
454 Include etc//extra/httpd-autoindex.conf -- 引入子配置文件
②修改子配置文件
vim /usr/local/apache2/etc/extra/httpd-autoindex.conf
21 Alias /icons/ "/usr/local/apache2//icons/" -- apache默认存放图片的位置
24 Options Indexes MultiViews -- MultiViews 多语言支持功能,国内开发可以不用设置MultiViews
29 Alias /shop/ "/usr/local/apache2/shop/"
30
31 <Directory "/usr/local/apache2/shop">
32 Options Indexes MultiViews
33 AllowOverride None
34 Require all granted
35 </Directory>
3).测试
192.168.0.104/shop/
2.虚拟主机实验
在一台服务器上,解析运行多个网站的技术;节约企业成本
访问网站的过程: 域名A --> IP --> 服务器 --> /目录A/index.html
域名B --> IP --> 服务器 --> /目录B/index.html
实验要求:在服务器上IP 192.168.0.104解析运行 www.sina.com www.souhu.com两个网站
1).域名解析 -- 使用文件解析
C:\Windows\System32\drivers\etc\hosts
里面内容默认都是注释掉的,添加:
192.168.0.104 www.sina.com
192.168.0.104 www.souhu.com
2).网站目录规划
mkdir -p /share/sina/
mkdir /share/sohu/
3).修改配置文件
①修改主配置文件
vim /usr/local/apache2/etc/httpd.conf
190 ServerName www.example.com:80
466 Include etc//extra/httpd-vhosts.conf
②修改子配置文件
vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
23 <Directory "/share/sina/"> -- sina目录权限
24 Options Indexes
25 AllowOverride None
26 Require all grandted
27 </Directory>
28
29 <Directory "/share/sohu/"> -- sohu目录权限
30 Options Indexes
31 AllowOverride None
32 Require all grandted
33 </Directory>
34
35 <VirtualHost 192.168.0.104> -- sina虚拟主机
36 ServerAdmin webmaster@sina.com
37 DocumentRoot "/share/sina/"
38 ServerName www.sina.com
39 # ServerAlias www.dummy-host.example.com
40 ErrorLog "logs/sina-error_log"
41 CustomLog "logs/sina-access_log" common
42 </VirtualHost>
43
44 <VirtualHost 192.168.0.104> -- sohu虚拟主机
45 ServerAdmin webmaster@sohu.com
46 DocumentRoot "/share/sohu/"
47 ServerName www.sohu.com
48 ErrorLog "logs/sohu-error_log"
49 CustomLog "logs/sohu-access_log" common
50 </VirtualHost>
4).重启服务
sto,sta
测试 www.sina.com www.sohu.com
3.rewrite重写重定向
域名跳转 www.sina.com 跳转到 www.sohu.com
1).修改配置文件
①修改主配置文件
vim /usr/local/apache2/etc/httpd.conf
147 LoadModule rewrite_module modules/mod_rewrite.so
②修改子配置文件
vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
29 <Directory "/share/sohu/">
30 Options Indexes FollowSymLinks -- 跳转、链接
31 AllowOverride all -- 打开.htaccess文件权限,进行跳转时候的判断
32 Require all granted
33 </Directory>
2).建立文件权限.htaccess
vim /share/sina/.htaccess
1 RewriteEngine on -- 重定向引擎功能,on开启,off关闭
2 RewriteCond %{HTTP_HOST} www.sina.com -- 进行判断(赋值),将www.sina.com赋值给地址栏
3 RewriteRule .* http://www.sohu.com -- 重写规则,“.*”代表匹配符合1.2条件后的所有
3).测试:sto sta www.sina.com --> www.sohu.com 301永久重定向
4.网页文件的跳转
要求:假如系统没有index5.html文件,访问www.sina.com/index5.html,会跳转到一个动态的index.php文件的位置,并且
显示文件的内容,对文件进行解析
1).修改权限文件..htaccess
vim /share/sina/.htaccess
1 RewriteEngine on
2 RewriteRule index(\d+).html index.php?id=$1 -- 当我们输入index数字.html时,就跳转到index.php文件
2).建立index.php文件
vim /share/sina/index.php
<?php
echo "Hello rewrite"
?>
3).测试
sto sta www.sina.com/index5.html
实现了静态文件向动态文件的跳转,伪静态:保护网站的安全 提升网站性能