阅读 48

[Linux]经典面试题 - 服务管理 - Apache

目录

一、Apache 概述

1.1 Apache 是什么?

  • Apache是一款跨平台运行的开源HTTP服务器软件。
  • 和很多软件一样,有源码编译安装和二进制数据包安装两种方式,可根据不同的需求进行选择,前者具有可根据企业要求定制的优点,后者具有方便快捷部署的优点。
    • 源码部署的配置文件一般在/usr/local/apache2/conf目录下
    • yum或者dnf包安装的配置文件一般在/etc/httpd/conf/httpd.conf目录下

1.2 Apache 和 Nginx 对比

  • Apache 拥有丰富的模块组件的支持,稳定性强,BUG少,对动态内容处理强。
  • Nginx 更为轻量级,占用资源少,负载均衡,并发性优秀,对静态内容处理高效。

二、Apache 安装部署

2.1 安装 Apache

  • 通过包管理器安装apache
dnf install httpd -y
  • 关闭SELinux和Firewalld(实际生产不推荐这么做)
systemctl stop firewalld
setenforce 0	#临时关闭

2.2 配置文件

  • 先备份,以防裂开
cp /etc/httpd/conf/httpd.conf{,.bak}
rm -f /etc/httpd/conf/httpd.conf
egrep -v "^ *#|^$" httpd.conf.bak > httpd.conf
  • 核心配置文件/etc/httpd/conf/httpd.conf

ServerRoot "/etc/httpd"

Listen 80


Include conf.modules.d/*.conf

User apache

Group apache

ServerAdmin root@localhost


    AllowOverride none
    Require all denied


DocumentRoot "/var/www/html"


    AllowOverride None
    Require all granted


    
    Options Indexes FollowSymLinks
    
    AllowOverride None
    
    Require all granted


    
    DirectoryIndex index.html


    Require all denied


ErrorLog "logs/error_log"

LogLevel warn

    
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    
    
    CustomLog "logs/access_log" combined


    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"


    AllowOverride None
    Options None
    Require all granted


    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml


AddDefaultCharset UTF-8

    MIMEMagicFile conf/magic

EnableSendfile on
IncludeOptional conf.d/*.conf

三、Apache 优化策略

3.1 404页面美化

vim httpd.conf
ErrorDocument 404 http://www.new404.com	#重定向到一个新的404页面。

(后续待补充)

原文:https://www.cnblogs.com/Skybiubiu/p/14964818.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐