zoukankan      html  css  js  c++  java
  • 26.Apache

    1.Apache简介

      Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源代码的网页服务器软件,可以在大多数电脑操作系统中运行,由于其跨平台和安全性(尽管不断有新的漏洞被发现,但由于其开放源代码的特点,漏洞总能被很快修补。因此总合来说,其安全性还是相当高的。)。被广泛使用,是最流行的Web服务器软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。

    2.安装

      1)查看是否安装httpd  

    [root@localhost ~]# rpm -qa httpd

      2)安装httpd  

    [root@localhost ~]# yum install httpd* -y
    Loaded plugins: fastestmirror, langpacks
    base                                                                             | 3.6 kB  00:00:00     
    extras                                                                           | 2.9 kB  00:00:00     
    updates                                                                          | 2.9 kB  00:00:00     
    updates/7/x86_64/primary_db                                                      | 4.5 MB  00:00:00     
    Loading mirror speeds from cached hostfile
     * base: mirrors.bfsu.edu.cn
     * extras: mirrors.bfsu.edu.cn
    。。。
    Dependency Updated:
      cyrus-sasl.x86_64 0:2.1.26-23.el7                  cyrus-sasl-gssapi.x86_64 0:2.1.26-23.el7           
      cyrus-sasl-lib.x86_64 0:2.1.26-23.el7              cyrus-sasl-md5.x86_64 0:2.1.26-23.el7              
      cyrus-sasl-plain.x86_64 0:2.1.26-23.el7            cyrus-sasl-scram.x86_64 0:2.1.26-23.el7            
      expat.x86_64 0:2.1.0-11.el7                        libdb.x86_64 0:5.3.21-25.el7                       
      libdb-utils.x86_64 0:5.3.21-25.el7                 openldap.x86_64 0:2.4.44-21.el7_6                  
    
    Complete!

      3)启动httpd服务,查看启动后的状态;   

    [root@localhost ~]# systemctl start httpd.service 
    [root@localhost ~]# systemctl status httpd.service 
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
       Active: active (running) since Tue 2020-09-15 11:36:25 CST; 11s ago
         Docs: man:httpd(8)
               man:apachectl(8)

     4)体验http服务  

    [root@linuxprobe ~]# firefox

      地址栏中输入http://127.0.0.1

      

    3.配置服务文件参数  

      在 httpd 服务程序的主配置文件中,存在三种类型的信息:注释行信息、全局配置、区域配置

      全局配置参数就是一种全局性的配置参数,可作用于对所有的子站点,既保证了子站点的正常访问,也有效减少了频繁写入重复参数的工作量。区域配置参数则是单独针对于每个独立的子站点进行设置的。

      1)httpd 服务程序的主要配置文件及存放位置

      

      2)配置httpd 服务程序时最常用的参数以及用途

        

      DocumentRoot 参数用于定义网站数据的保存路径,其参数的默认值是把网站数据存放到/var/www/html 目录中;而当前网站普遍的首页面名称是index.html,因此可以向/var/www/html 目录中写入一个文件,替换掉httpd 服务程序的默认首页面,该操作会立即生效。  

    root@localhost html]# echo "hello, thank you" > /var/www/html/index.html

      

     3)在默认情况下,网站数据是保存在/var/www/html 目录中,将保存网站数据的目录修改为/home/wwwroot 目录:

        建立网站数据的保存目录,并创建首页文件。  

    [root@localhost html]# mkdir /home/wwwroot
    [root@localhost html]# echo "The New Web Directory" > /home/wwwroot/index.html

      打开httpd 服务程序的主配置文件,将约第119 行用于定义网站数据保存路径的参数DocumentRoot 修改为/home/wwwroot,同时还需要将约第124 行用于定义目录权限的参数Directory 后面的路径也修改为/home/wwwroot。配置文件修改完毕后即可保存并退出。  

    [root@localhost html]# vim /etc/httpd/conf/httpd.conf 
    DocumentRoot: The directory out of which you will serve your
    116 # documents. By default, all requests are taken from this directory, but
    117 # symbolic links and aliases may be used to point to other locations.
    118 #
    119 DocumentRoot "/home/wwwroot"
    120
    121 #
    122 # Relax access to content within /var/www.
    123 #
    124 <Directory "/home/wwwroot">
    125 AllowOverride None
    126 # Allow open access:
    127 Require all granted
    128 </Directory>
    ………………省略部分输出信息………………

        重新启动httpd 服务程序并验证效果,浏览器刷新页面后的内容如图10-6 所示。在尝试访问http://127.0.0.1/index.html 页面时,竟然发现页面中显示“Forbidden,You don't have permission toaccess /index.html on this server.”。而这一切正是SELinux 在捣鬼。

  • 相关阅读:
    搜索引擎的变化 【转载】
    转贴:Apache重负荷服务器应如何优化
    开源WebGIS系统构建工具集合
    linux命令大全
    英语新闻常用搜索引擎 【转载】
    转载王垠的《完全用GNU/Linux工作》!!!
    国内外搜索引擎论坛 【转载】
    刚刚申请的WebGIS应用QQ群,最大用户80,欢迎加入啊!
    转贴:用Apache反向代理设置对外的WWW和文件服务器
    sourceforge.net上的GeoServer的下载地址列表
  • 原文地址:https://www.cnblogs.com/xinghen1216/p/13686144.html
Copyright © 2011-2022 走看看