【笔记】Apache服务配置

Apache服务配置


###一. 世界使用量最高的web服务器     httpd

        url = http://www.sina.com.cn:80/admin/index.php
        
        
###二. 安装
        1. LAMP源码包编译安装 
           
           生产环境  安全 稳定
           
           开发环境

        2. 二进制包安装  yum 
        
        
###三. 相关文件

        配置文件
                /usr/local/apache2/etc/httpd.conf  主配置文件
                /usr/local/apache2/etc/extra/httpd-*.conf  子配置文件
                
        网站默认保存目录 /usr/local/apache2/htdocs/ 
        
        日志保存目录  /usr/local/apache2/logs/ 

        tail -f  access_log   动态查看文件内容
        
        日志处理:  access_log   error_log 
        
        vim /etc/logrotate.conf 
        
         35 /usr/local/apache2/logs/access_log {
          36     daily
         37     rotate 30
         38 }
         39 
         40 /usr/local/apache2/logs/error_log {
         41     daily
         42     rotate 30
         43 }


       logrotate -f /etc/logrotate.conf 手动执行文件 查看日志
       
       
###四. 配置文件

        命令别名   alias
        vim ~/.bashrc
        alias sto='/usr/local/apache2/bin/apachectl stop'
        alias sta='/usr/local/apache2/bin/apachectl start'

        source ~/.bashrc
        
        sto
        sta
        
        vim /usr/local/apache2/etc/httpd.conf

                
####实验1 目录别名  扩展网站目录  增加服务器

        1.修改主配置文件
          vim /usr/local/apache2/etc/httpd.conf
          453 Include etc//extra/httpd-autoindex.conf
        2.修改子配置文件
          vim /usr/local/apache2/etc/extra/httpd-autoindex.conf
           29 Alias /bbs/ "/usr/local/apache2/bbs/"
            30 
           31 <Directory "/usr/local/apache2/bbs/">
           32     Options Indexes
           33     Allowoverride None
           34     Require all granted
           35 </Directory>

        3.建立目录 /usr/local/apache2/bbs
          mkdir  /usr/local/apache2/bbs/
          vim index.html
          
        4.重启服务  测试 
        
          sto
          sta 
          
          测试   192.168.184.252/bbs/
          
    
####实验2 虚拟主机 

        1.域名解析   文件解析 
          C:\Windows\System32\drivers\etc\hosts
          192.168.184.252  www.sina.com
          192.168.184.252  www.sohu.com
          
        2.网站目录规划   
           mkdir  -p /share/sina    --  www.sina.com        
           mkdir  /share/sohu       --  www.sohu.com
           
           vim /share/sina/index.html
           vim /share/sohu/index.html
           
        3.修改主配置文件
          vim /usr/local/apache2/etc/httpd.conf
          465 Include etc//extra/httpd-vhosts.conf
          
        4.修改子配置文件
          vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
           23 <Directory "/share/sina">
           24     Options Indexes
           25     AllowOverride None
           26     Require all granted
           27 </Directory>
           28     
           29 <Directory "/share/sohu">
           30     Options Indexes
           31     AllowOverride None
           32     Require all granted
           33 </Directory> 
           34     
           35 <VirtualHost 192.168.184.252>
           36     ServerAdmin webmaster@sina.com
           37     DocumentRoot "/share/sina/"
           38     ServerName www.sina.com
           39     ErrorLog "logs/sina-error_log"
           40     CustomLog "logs/sina-access_log" common
           41 </VirtualHost>
           42 
           43 <VirtualHost 192.168.184.252>
           44     ServerAdmin webmaster@sohu.com
           45     DocumentRoot "/share/sohu/"
           46     ServerName www.sohu.com
           47     ErrorLog "logs/sohu-error_log"
           48     CustomLog "logs/sohu-access_log" common
           49 </VirtualHost>

        5. 重启服务  测试
        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
          2.修改子配置文件(虚拟主机文件)
            vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
             23 <Directory "/share/sina">
             24     Options Indexes FollowSymLinks
             25     AllowOverride All 
             26     Require all granted
             27 </Directory>

          3. 建立权限文件.htaccess
            vim /share/sina/.htaccess
              1 RewriteEngine on
              2 RewriteCond %{HTTP_HOST} www.sina.com
              3 RewriteRule .* http://www.sohu.com

          4. 重启服务  测试
              sto
              sta
              
              测试  www.sina.com -> www.sohu.com
              
         
         网页文件跳转 
             1.修改权限文件
             vim  /share/sina/.htaccess
               1 RewriteEngine on
                2 RewriteRule index(\d+).html  index.php?id=$1
                
              2.建立 index.php 文件
              vim /share/sina/index.php
              <?php   echo "hello  reWrite"; ?>
              
              重启服务  测试
              sto 
              sta  
              
              测试   www.sina.com/index5.html

posted on 2017-06-30 19:31  roadone  阅读(148)  评论(0)    收藏  举报