目录
切换使用MPM
编辑/etc/httpd/conf.modules.d/00-mpm.conf文件):
//LoadModule mpm_NAME_module modules/mod_mpm_NAME.so //NAME有三种,分别是: prefork event worker
访问控制法则
法则 | 功能 |
---|---|
Require all granted | 允许所有主机访问 |
Require all deny | 拒绝所有主机访问 |
Require ip IPADDR | 授权指定来源地址的主机访问 |
Require not ip IPADDR | 拒绝指定来源地址的主机访问 |
Require host HOSTNAME | 授权指定来源主机名的主机访问 |
Require not host HOSTNAME | 拒绝指定来源主机名的主机访问 |
httpd-2.4版本默认是拒绝所有主机访问的,所以安装以后必须做显示授权访问
虚拟主机类型
虚拟主机有三类:
-
相同IP不同端口
-
不同IP相同端口
-
相同IP相同端口不同域名
配置前戏
//设置主机名 [root@localhost ~]# vim /etc/httpd/conf/httpd.conf # If your host doesn't have a registered DNS name, enter its IP address here. ServerName www.example.com:80 //取消此行前面的#号 ...... [root@localhost ~]# find / -name *vhosts.conf //全局查找一下httpd的模板文件 /usr/share/doc/httpd/httpd-vhosts.conf [root@localhost ~]# cd /etc/httpd/conf.d/ [root@localhost conf.d]# ls README autoindex.conf userdir.conf welcome.conf [root@localhost conf.d]# cp /usr/share/doc/httpd/httpd-vhosts.conf . [root@localhost conf.d]# ls //将查找的文件复制到conf.d/下 README autoindex.conf httpd-vhosts.conf userdir.conf welcome.conf [root@localhost conf.d]# vim httpd-vhosts.conf <VirtualHost *:80> //配置好的模板 DocumentRoot "/var/www/dummy-host.example.com" //网站根目录 ServerName dummy-host.example.com //域名 ErrorLog "/var/log/httpd/dummy-host.example.com-error_log" //错误日志 CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common //访问日志 </VirtualHost>
相同IP不同端口
[root@localhost ~]# cd /etc/httpd/conf.d [root@localhost conf.d]# vim httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/var/www/html/tanke" ServerName www.tanke.com ErrorLog "/var/log/httpd/www.tanke.com-error_log" CustomLog "/var/log/httpd/www.tanke.com-access_log" common </VirtualHost> Listen 81 <VirtualHost *:81> DocumentRoot "/var/www/html/doudizhu" ServerName www.doudizhu.com ErrorLog "/var/log/httpd/www.doudizhu.com-error_log" CustomLog "/var/log/httpd/www.doudizhu.com-access_log" common </VirtualHost> [root@localhost html]# ls //进入html目录下,下载坦克大战,斗地主所需源码包 ''$'\345\235\246\345\205\213''.zip' ''$'\346\226\227\345\234\260\344\270\273''.zip' [root@localhost html]# unzip 坦克.zip //直接解压,如无zip,需下载 [root@localhost html]# unzip 斗地主.zip [root@localhost html]# ls Battle_City 'HTML5 canvas#U79fb#U52a8#U7aef#U6597#U5730#U4e3b#U5c0f#U6e38#U620f' ''$'\345\235\246\345\205\213''.zip' ''$'\346\226\227\345\234\260\344\270\273''.zip' [root@localhost html]# rm -rf 坦克.zip //删除压缩包 [root@localhost html]# rm -rf 斗地主.zip [root@localhost html]# ls Battle_City 'HTML5canvas#U79fb#U52a8#U7aef#U6597#U5730#U4e3b#U5c0f#U6e38#U620f' [root@localhost html]# mv Battle_City/ tanke //修改目录名称 [root@localhost html]# mv HTML5\ canvas#U79fb#U52a8#U7aef#U6597#U5730#U4e3b#U5c0f#U6e38#U620f/ doudizhu [root@localhost html]# ls //查看是否出错 doudizhu tanke [root@localhost html]# cd tanke [root@localhost tanke]# ls audio css images index.html js [root@localhost html]# httpd -t //查看配置文件是否出错 Syntax OK [ro