Apache

来源:互联网 发布:asp.net js 隐藏控件 编辑:程序博客网 时间:2024/06/18 05:17

Apache

1.Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算器平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Pytho等解释器编译到服务器中。

2.在本机查看常用网站的服务器类型

www.baidu.com

www.sogo.com

www.taobao.com

www.youku.com

3.Apache  安装部署
   1.安装httpd服务
       yum install -y  httpd   
       systemctl start httpd
       systemctl enable httpd


   2.关闭防火墙
       systemctl stop  firewalld
       systemctl disable firewalld


   3.测试:通过网页访问172.25.254.106
       http://172.25.254.106


   4.安装Apache手册
       yum install -y httpd-manual
       systemctl restart httpd  ##重启之后manual生效
       测试:http://172.25.254.106/manual  可以查看手册

4.Apache基础信息
   1.查看httpd主配置文件
       rpm -qc httpd


   2.查看httpd默认端口
       ss -antlupe | grep httpd        http服务默认端口为80端口


   3.默认发布目录
       /var/www/html     119行显示的是默认发布目录

           
4.默认发布文件
  index.html     


5.默认端口
  80       42行显示的是http服务默认端口是80


6.修改默认发布文件
  vim /var/www/html/test


vim /etc/httpd/conf/httpd.conf
  164行  DirectoryIndex  test index.html 



默认发布文件可以为多个,顺序越前越优先,如果发布文件都不存在,则默认访问Apache网页
7.修改默认端口
  vim /etc/httpd/conf/httpd.conf
  43行  LIsten 8080

测试:在浏览器网址栏输入172.25.254.106:8080


8.修改默认发布目录
  新建一个目录 mkdir /www/html
  在目录里面建立index.html文件 


  编辑index.html文件
  <h1>/www/html's page</h1>

 
  vim /etc/httpd/conf/httpd.conf  编辑主配置文件
    120  DocumentRoot "/www/html"
    121  <Directory "/www/html">
    122       Require all granted
    123  </Directory>

 
  systmctl  restart   httpd
  semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'
  restorecon -FvvR /www/


6.Apache的虚拟主机   一台主机可以发布多个站点
     1.建立虚拟主机的默认发布目录
         mkdir /var/www/virtual/news/html -p
         mkdir /var/www/virtual/music/html -p


    2.在默认发布目录下编辑index.html文件
       vim /var/www/virtual/news/html/index.html
       <h1>news.westos.com</h1>
     vim /var/www/virtual/music/html/index.html
      <h1>news.music.com</h1>


3.在/etc/httpd/conf.d建立配置文件
  vim a_dfaults.conf
      <VirtualHost _default_:80>
        DocumentRoot /var/www/html
        CustomLog "logs/default.log" combined
     </VirtualHost>


  vim news.conf
    <VirtualHost *:80>
        ServerName news.westos.com
        DocumentRoot /var/www/virtual/news/html
        Customlog "logs/news.log" combined
    </VirtualHost>

<Directory "/var/www/virtual/new/html">

           Require all granted

</Directory>



  vim music.conf
    <VirtualHost *:80>
        ServerName music.westos.com
        DocumentRoot /var/www/virtual/music/html
        Customlog "logs/music.log" combined
    </VirtualHost>

<Directory "/var/www/virtual/music/html">

           Require all granted

</Directory>


systmctl  restart   httpd
4.在客户端/etc/hosts编辑指向
172.25.254.106 www.westos.com news.westos.com music.westos.com


测试:在浏览器网页栏输入www.westos.com  news.westos.com   music.westos.com


------------------------------------------------------------
7.Apache黑白名单
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html   ##在发布目录下建立index.html
   www.westos.com 


vim a_dfaults.conf
    <Directory "var/www/html/westos">
            Order Allow,Deny
            Allow from All
            Deny from 172.25.254.30    
    </Directory>


systmctl  restart   httpd
只拒绝172.25.254.30这台主机访问,其他主机都允许
按照列表的先后顺序进行读取,后读取的会覆盖先读取的内容


8.用户方式的访问     
mkdir /var/www/html/admin       ##建立目录
vim /var/www/html/admin/index.html    ##在发布目录下建立index.html
   www.admin.com


htpasswd -cm /etc/httpd/userpass admin   ##在/etc/httpd/目录下建立userpass文件,并生成admin用户
htpasswd -m /etc/httpd/userpass admin1


可以使用cat  /etc/httpd/userpass命令查看建立的文件的情况


vim a_dfaults.conf
    <Directory "var/www/html/admin">
        AuthUserFile /etc/httpd/userpass
        AuthName "input name and passwd"  ##提示语
        AuthType basic  
        Require user admin    指定用户admin可以登陆
        #Require  valid-user    所有用户
    </Directory>

systmctl  restart   httpd
通过真机浏览器访问172.25.254.106/admin,只有在配置文件里面允许的用户才可查看内容,不允许的用户则不能查看

在登陆时需要输入用户admin  以及密码之后才可以登陆,如果在配置文件指定的是所有用户,则所有用户都可以访问,如果只是指定个别用户,则指定的用户才可以登陆,其他用户并没有权限访问


9.Apache支持的语言
1.php
yum install -y php  ##安装php服务
vim /var/www/html/index.php    
    <?php
            phoinfo();

    ?>


systemctl restart httpd
vim /etc/httpd/conf/httpd.conf

163行修改默认发布文件的顺序,将index.php放在第一个


systemctl restart httpd

然后通过真机浏览器访问172.25.254.106/index.php,就可以看到php的图片


2.cgi
vim /var/www/cgi-bin/index.cgi   #在 /var/www/cgi-bin/目录下创建index.cgi文件,并进行编辑
    #!/usr/bin/perl
    print "Content-type:text/html\n\n ";

    print`date`;


chmod +x /var/www/cgi-bin/index.cgi

alias /cgi   /var/www/cgi-bin/

vim a_dfaults.conf      对配置文件进行设置
    <Directory "var/www/cgi-bin">
            Options +ExecCGI
            AddHandler cgi-script .cgi
    </Directory>

<Directory "/var/www/cgi-bin">

         Require all granted

</Directory>

vim /etc/http/conf/httpd.conf

将index.cgi放在默认发布文件最前面

然后通过浏览器访问http://172.25.254.106/cgi就可以看到脚本执行的结果


原创粉丝点击