WEB


web 服务器: 
                  web 服务器通常指网站服务器,能够向浏览器等 web 客户端提供文档、文件、图片( 静态 )、动态页面等;能够向全世界的人下载、浏览
          
     静态页面:通常指图片、  *.txt html
     动态页面:语言( php  asp  jsp  .net ) ——> apache 调用( php - cgi ) ——> 解析结果 ——> apache +——> client
        
      http : //www.baidu.com:80 —> IP 
      url  : //host: port —> apache( 静态页面 ) ——> 调用相应模块进行解析 ——> 结果返还给 apache ——> client
      ftp  : //vm1.uplooking.com
 
 ——>     web 架构:
      
                LAMP = Linux + Apache + MySQL + PHP     ; LNMP = Linux + Nginx + MySQL + PHP
     
            PHP 、JSP
     
            WEB ( Linux + Apache + MySQL + PHP ) ——>  web + MySQL ——> ( web1 + web2 )+ MySQL ——>  ...
            
  
     端口 80
  Apache : 是著名的 web 服务器软件,由Apache 软件基金会负责开发维护
      一、开放源码
      二、跨平台
      三、支持模块化设计                         Apache 官网:
www.apache.org
      四、安全稳定
            
  

      
 ——> 搭建 web 服务:
              
      一、 关闭防火墙和selinux
     
      二、  配置yum 源
     
      三、 软件三部曲(查看、安装、查看软件列表)
     
              1> 安装好软件、查看
                      #rpm  -aq|grep  httpd
                          httd-tools-2.2.15-29.el6_4.x86_64      工具包
                          httpd-2.2.15-29.el6_4.x86_64       server 端软件
php

                       #yum   -y   install   httpd-manual.noarch    安装帮助手册
             
              2> 启动服务、查看帮助手册
                     #service   httpd  start
                    
                     #firefox  
http://127.0.0.1           ——> 查看帮助手册
                     #firefox   
http://www.jinbuguo.com/apache/menu22/       ——> 中文版帮助手册(参考)
     
              3> 查看配置文件  #rpm  - ql   httpd
                      /etc/httpd 服务主目录
                      /etc/httpd/conf 相关目录
                      /etc/httpd/conf.d 相关子目录(子配置文件)
                      /etc/httpd/conf.d/README  说明书
                      /etc/httpd/conf.d/welcome.conf 欢迎页面(redhat广告页)
                      /etc/httpd/conf/httpd.conf 主配置文件
html

                      /etc/httpd/logs  日志文件存放位置  和  /var/log/httpd 互为硬连接
                      /etc/httpd/modules   httpd服务相应的模块
                      /etc/httpd/run  进程 和  /var/run/httpd互为硬连接
                      /etc/logrotate.d/httpd  日志轮巡
                      /etc/rc.d/init.d/htcacheclean apache官方启动脚本
                      /etc/rc.d/init.d/httpd   启动脚本
linux

                      /usr/sbin/httpd   二进制命令
                      /var/log/httpd  
                      /var/run/httpd
                      /var/www    数据根目录
                      /var/www/html    静态页面的数据根目录
web

     
       四、 了解配置文件
     
      五、  经过修改配置文件来完成服务搭建
      
             需求 1 :访问默认网站
                   一、默认数据目录   /var/www/html
                         #echo  this  is  default   test   page!  > /var/www/html
                  
                   二、启动服务
                          #service   httpd  restart
                              Stopping httpd:                                            [  OK  ]
                      
                      解决:
                           #vim /etc/httpd/conf/httpd.conf
                              ...
                              ServerName  server.uplooking.com:80
apache

                  
                   三、测试验证
                         1>   #yum   -y  install    elinks    ——> 安装 elinks 软件( 超文本解析 )
                                #elinks   
http://192.168.1.102    ——> 查看网站
                        
                         2>  firefox 
http://server.uplooking.com    ——> 查看网站
     
     
             需求 2 :共享本地目录下的文件
            
                   方法一: 经过软连接方式共享
                           #mkdir   /data
                           # touch   /data/file{1..5}
                          
                           #ln  -s   /data      /var/www/html/notes
                          
                   方法二: 经过别名方式共享       ——> 访问时必须写的与别名相同 
                          # vim  /etc/httpd/conf/httpd.conf
                              ...              别名
                              Alias   /soft/    "/software/"          在主配置文件最后添加
                              <Directory "/software">   开始给/software目录受权
                                 Options Indexes MultiViews FollowSymLinks   支持索引支持软连接
                                 AllowOverride None    不支持 htaccess文件
                                 Order allow,deny    order排序,先容许后拒绝
                                 Allow from all      容许全部人
                              </Directory>
vim

                         #service   httpd   restart
                        
                     .223 访问:  firefox  
http://192.168.1.123/soft/
      
 
一、 若是不肯意让其看见共享目录里的内容,去掉支持索引选项
 二、若是http 服务只是共享一些文件,不须要浏览网页,那么能够将 /etc/httpd/conf/welcome.conf 文件重命名,而后重启服务 
http://127.0.0.1   能看到默认数据家目录里的文件
 
 
             需求 3 :更改默认数据家目录
                          # mkdir   /webroot      ——> 建立新数据根目录
                         
                    1> #vim /etc/httpd/conf/httpd.conf
                            ...
                            DocumentRoot "/webroot"   定义数据根目录
浏览器

                            <Directory "/webroot">   给目录受权
                                Options Indexes FollowSymL
                                Order allow,deny
                                Allow from all
                            </Directory>
                    
                      2> # service httpd restart
                               Stopping httpd:                                            [  OK  ]
                               Starting httpd: Syntax error on line 293 of /etc/httpd/conf/httpd.conf:
                               DocumentRoot must be a directory
                                                                                                 [FAILED]
                     失败缘由:没有建立该目录
安全

    
 
需求 4 :基于用户名和密码认证的访问 ——> 跟本地有没有该用户没有关系
          
                     user01( 本地用户) 和 stu1( 本地没有) 用户经过密码访问首页文件
          
               一、修改配置文件
                   #vim  /etc/httpd/conf/httpd.conf
                       ...
                       <Directory "/webroot">
                           AuthType Basic   开启基本认证
                           AuthName "Input your name &password:"   提示信息
                           AuthUserFile /etc/httpd/conf/.htpassword    指定密码文件
                           #Require user user01     指定用户访问
                           #Require valid-user user01,stu1   指定多个用户
                           AuthGroupFile /etc/httpd/conf/groups    指定组的文件
                           Require group admin  指定哪一个组
服务器

                           Options Indexes FollowSymLinks
                           AllowOverride None
                           Order allow,deny
                           Allow from all
                       </Directory>
         
               二、建立密码文件并将用户加入到密码文件中
                 htpasswd:
                          -c:建立新的密码文件
                          -m:md5加密
                           -b:取消交互
网络

                         # htpasswd -cm .htpassword user01     添加用户到密码文件里
                         # htpasswd -bm .htpassword stu1 123    取消交互添加,直接写密码
                         # cat .htpassword
                              user01:$apr1$MffdS1m6$32MjzgnT/2YDDEMZeUt/P0
                              stu1:$apr1$93MFv7Vo$aTrtUftbBobzl34jtX4PM.
          
               三、 重启服务测试验证      #service  httpd  restart 
              
                       
          
 
 总结:
   一、容许某一我的经过用户名密码访问,必须将其加入密码文件里,配置文件里参数:Require  user    username
   二、容许多我的经过用户名密码访问,必须将其加入密码文件里,配置文件参数:Require valid-user username1,username2
   三、容许多我的经过用户名密码访问,必须将其加入密码文件里,配置文件里参数:指定一个组文件,AuthGroupFile /etc/httpd/conf/groups      Require group admin
            
四、用户能够不在本地操做系统存在

             
             
          需求 5 :对于网络中的虚拟机进行访问控制                           Order     allow,deny       先容许后拒绝,若是allow 和deny 冲突,deny 优先                 Order    deny,allow       先拒绝后容许,若是冲突,allow 优先                                Allow  from  address                 Deny from 205.252.46.165                 Deny from host.example.com  一、拒绝大部分,容许少数                                二、 容许大部分,拒绝少部分       Order deny,allow                                                  Order allow,deny       Deny from all                                                        Allow from all       Allow from dev.example.com                                  Deny from 192.168.1.2  192.168.1.3                                                                                   Deny from 10.1.1.0/255.255.255.0  uplooking.com

相关文章
相关标签/搜索