Web安全
基础漏洞
01前端基础【HTML】
02前端基础【CSS】
03后端基础【PHP速通】
04后端基础【PHP面向对象】
05MySQL基础操作
06前后端联动【代码练习】
07SQL注入【1】
07SQL 注入【2】
08SQL注入 Labs
08SQL注入速查表
09XSS
09跨站脚本攻击【XSS】
09XSS Labs
10跨站请求伪造【CSRF】
11服务器端请求伪造【SSRF】
12XML 外部实体注入【XXE】
13代码执行漏洞
14命令执行漏洞
15文件包含漏洞
16文件上传漏洞
17反序列化漏洞
18业务逻辑漏洞
19未授权访问漏洞集合
20跨源资源共享【CORS】
21SSTI模板注入
22并发漏洞
23点击劫持【Clickjacking 】
24请求走私
25路径遍历
26访问控制
27身份验证漏洞
28WebSocket
29Web缓存中毒
30HTTP 主机头攻击
31信息泄露漏洞
32原型污染
33NoSQL注入
API 安全
01web应用程序
02HTTP协议
03API概述
04分类类型
05交换格式
06身份验证
07常见API漏洞
08crAPI靶场
09JWT
10OAuth 2.0身份验证
11GraphQL【1】
11GraphQL【2】
12DVGA靶场
13服务器端参数污染
14API文档
15API Labs
16OAuth Labs
17GraphQL API Labs
18JWT Labs
小程序
小程序抓包
数据库
MySQL
Oracle
MongoDB
Redis
PostgreSQL
SQL server
中间件
Nginx
Apache HTTP Server
IIS
Tomcat
框架
ThinkPHP
Spring
Spring Boot
Django
访问控制
-
+
首页
Apache HTTP Server
 ## 概述 Apache HTTP Server(通常简称Apache)是一个开源的、跨平台的Web服务器软件,由Apache软件基金会开发和维护。 自1995年问世以来,Apache长期占据Web服务器市场的主导地位,直到2019年左右被Nginx超越。它仍然是世界上最流行和广泛使用的Web服务器软件之一,为全球数百万网站提供支持。 Apache的名字源自"a patchy server"(一个补丁式的服务器),反映了其早期开发方式是通过多个补丁组合而成,但现在这个名称已经与美洲原住民的阿帕奇族联系在一起。 官网地址:https://httpd.apache.org 官网文档地址:https://httpd.apache.org ## 特点 **开源免费**:Apache是免费软件,遵循Apache许可证2.0发布,允许自由使用和修改; **跨平台支持**:可在几乎所有主流操作系统上运行,包括Unix、Linux、Windows、macOS等; **模块化设计**:核心功能精简,通过模块系统扩展功能,可按需加载模块; **高度可配置**:通过文本配置文件实现高度灵活的自定义配置; **强大社区支持**:拥有庞大的用户和开发者社区,提供丰富的文档和支持资源; **支持多种编程语言**:通过模块支持PHP、Python、Perl等多种语言; **.htaccess文件**:支持目录级配置,允许用户在不修改主配置的情况下自定义设置。 ## 核心功能 **基础 Web 服务** 支持 HTTP/1.1、HTTP/2(需模块mod_http2),提供静态文件(HTML、CSS、JS、图片等)传输、目录索引、MIME 类型解析等基础功能。 **虚拟主机(Virtual Host)** 允许在单台服务器上部署多个网站(通过域名或端口区分),每个网站可独立配置根目录、日志、权限等,例如同时部署example.com和test.com。 **安全功能** - **SSL/TLS 加密**:通过mod_ssl模块支持 HTTPS,可配置 SSL 证书实现数据传输加密。 - **认证与授权**:通过mod_auth_basic、mod_auth_digest实现用户密码认证,通过mod_access_compat控制 IP / 域名访问权限。 - **防攻击**:支持限制请求速率(mod_ratelimit)、防御 DDoS(通过模块或第三方工具集成)。 **URL 重写与转发** 通过mod_rewrite模块实现 URL 美化(如/user/123映射到/user.php?id=123)、301/302 重定向、条件跳转等。 **动态内容支持** 与 PHP、Python、Perl 等脚本语言无缝集成(通过mod_php、mod_wsgi等模块),支持 CGI、FastCGI 协议处理动态请求。 **日志与监控** 记录访问日志(access.log)和错误日志(error.log),支持自定义日志格式,可结合工具(如 AWStats、GoAccess)分析访问数据。 **缓存与压缩** 通过mod_cache实现内容缓存,减少重复请求处理;通过mod_deflate压缩响应数据(如 Gzip),降低传输带宽。 ## 适用场景 **中小型网站与博客** 对配置灵活性要求高,需支持 PHP 等动态语言(如 WordPress、Drupal),Apache 的模块化设计和 PHP 集成优势明显。 **企业内部系统** 注重稳定性和兼容性,需部署多个应用(如 OA 系统、CRM),虚拟主机功能可简化多站点管理。 **动态内容为主的应用** 如电商网站、论坛,需频繁处理用户交互和数据库请求,prefork 模式的稳定性更适合动态请求处理。 **需要复杂 URL 重写的场景** 如 SEO 优化(URL 美化)、路径跳转,mod_rewrite模块的规则引擎支持复杂条件逻辑。 **低成本服务器部署** 对硬件资源要求不极端(相比 Nginx,高并发下内存占用较高),适合中小型服务器配置。 ## 优劣势 **优势** 稳定性极强:经过数十年迭代,在各种环境下运行稳定,崩溃概率低,适合生产环境。 模块生态丰富:官方及第三方模块超过数百个,覆盖安全、缓存、动态语言等几乎所有需求。 配置灵活:支持.htaccess 文件实现目录级配置(无需重启服务),适合非 root 用户管理网站。 动态内容处理优秀:与 PHP 等脚本语言的集成度高,默认配置即可运行大多数动态应用。 **劣势** 高并发性能较弱:相比 Nginx,在处理十万级以上并发连接时,内存和 CPU 占用更高,响应速度较慢。 配置复杂度高:主配置文件和模块配置交织,新手易出错(如虚拟主机规则冲突)。 默认设置优化不足:需手动调整 MPM 参数(如进程 / 线程数量)以适配高负载场景,否则性能受限。 ## 目录结构 **核心配置目录: /etc/apache2** Apache 配置文件的主目录,所有核心配置、虚拟主机、模块开关等均存放在此。 | 目录 / 文件 | 功能说明 | | ---------------- | ------------------------------------------------------------ | | apache2.conf | Apache 主配置文件,包含全局基础配置(如运行用户、超时时间、模块加载规则等),是配置的 “入口”。 | | ports.conf | 配置 Apache 监听的端口(默认监听 80 端口,HTTPS 配置后会增加 443 端口)。 | | sites-available/ | 存放可用的虚拟主机配置文件(未启用状态),每个文件对应一个网站的配置(如example.com.conf)。 | | sites-enabled/ | 存放已启用的虚拟主机配置文件,通过软链接关联到sites-available/中的文件(由a2ensite命令创建)。 | | mods-available/ | 存放可用的模块配置文件,每个模块对应两个文件:.load(加载模块)和.conf(模块参数配置,如rewrite.load、ssl.conf)。 | | mods-enabled/ | 存放已启用的模块配置文件,通过软链接关联到mods-available/中的文件(由a2enmod命令创建)。 | | conf-available/ | 存放可用的补充配置片段(如压缩、缓存的全局配置,非虚拟主机专属)。 | | conf-enabled/ | 存放已启用的补充配置片段,通过软链接关联到conf-available/中的文件(由a2enconf命令创建)。 | | envvars | 定义 Apache 环境变量(如运行用户www-data、日志目录路径等)。 | **网站内容目录: /var/www** 默认存放网站文件的根目录,可通过虚拟主机配置自定义路径。 | 目录 / 文件 | 功能说明 | | --------------------------------- | ------------------------------------------------------------ | | html/ | Apache 默认网站的根目录(对应默认虚拟主机),初始包含index.html测试页面。 | | 自定义目录(如example.com/html/) | 用户为虚拟主机创建的独立网站目录(如/var/www/example.com/html),存放对应网站的 HTML、CSS、JS 等文件。 | **日志目录:/var/log/apache2/** 存放 Apache 的访问日志和错误日志,便于排查问题和分析访问情况。 | 日志文件 | 功能说明 | | -------------------------------------- | ------------------------------------------------------------ | | access.log | 默认虚拟主机的访问日志,记录所有访问请求(IP、时间、URL、状态码等)。 | | error.log | 默认虚拟主机的错误日志,记录服务器运行中的错误(如文件不存在、权限问题等)。 | | 自定义日志(如example.com.access.log) | 虚拟主机专属日志,通过虚拟主机配置文件中的CustomLog和ErrorLog指定(如/var/log/apache2/example.com.access.log)。 | **模块文件目录:/usr/lib/apache2/modules/** 存放 Apache 的核心模块和扩展模块的二进制文件(.so格式),如: - mod_rewrite.so:URL 重写模块 - mod_ssl.so:HTTPS 加密模块 - mod_php8.1.so:PHP 解析模块(需单独安装) 模块通过mods-available/中的.load文件加载(如rewrite.load中包含LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so)。 **二进制文件与服务脚本** | 路径 | 功能说明 | | ----------------------------------- | ------------------------------------------------------------ | | /usr/sbin/apache2 | Apache 主程序二进制文件,启动服务时实际运行的程序。 | | /usr/sbin/apache2ctl | Apache 控制脚本,用于检查配置(apache2ctl configtest)、重启服务等。 | | /lib/systemd/system/apache2.service | systemd 服务配置文件,用于通过systemctl管理 Apache(启动、停止、开机自启等)。 | **用户级配置:.htaccess** Apache 支持在网站目录中创建.htaccess文件,实现目录级配置覆盖(无需修改主配置),常见用途: - URL 重写规则(如 WordPress 的固定链接) - 目录访问认证(密码保护) - MIME 类型设置 注意:.htaccess的生效需在虚拟主机配置中开启AllowOverride All(如之前示例中的\<Directory>块配置)。 ## apache2.conf apache2.conf 主配置文件,包含 Apache 运行的全局核心配置,定义了服务器的基础行为(如运行用户、超时时间、目录权限等),并通过 Include 指令关联其他配置文件(如虚拟主机、模块配置等)。 按功能分为多个逻辑块,整体结构清晰,主要包括: - 服务器基础配置(标识、根目录、运行用户等) - 资源限制与连接设置(超时、并发控制等) - 目录权限控制(全局目录访问规则) - 日志与错误配置 - 模块与其他配置文件的引入(通过 Include 指令) **服务器标识与根目录** ```txt # 服务器标识(对外展示的信息,影响安全性) ServerTokens OS # 响应头中包含的服务器版本信息(可选:Full/OS/Min/Minor/Major/Prod) # 推荐设为 Prod(仅显示 "Apache",隐藏版本和系统信息,减少攻击面) ServerSignature On # 错误页面底部是否显示服务器版本和主机名(Off 可隐藏) # 服务器根目录(Apache 配置文件的基准目录) ServerRoot "/etc/apache2" # 所有相对路径的基准(如日志、模块路径) ``` **运行用户与进程设置** ```txt # 运行 Apache 进程的用户和组(默认使用 www-data,确保网站目录权限适配) User www-data Group www-data # 进程 ID(PID)文件路径 PidFile ${APACHE_PID_FILE} # 变量在 /etc/apache2/envvars 中定义,默认路径:/var/run/apache2/apache2.pid ``` **连接与超时设置** 控制客户端连接的生命周期,影响服务器性能和资源占用: ```txt # 连接超时(客户端建立连接后,未发送请求的最大等待时间,单位:秒) Timeout 300 # 长连接设置(复用已建立的 TCP 连接,减少握手开销) KeepAlive On # 是否启用长连接(高并发静态资源场景建议开启) MaxKeepAliveRequests 100 # 单个长连接可处理的最大请求数(0 表示无限制) KeepAliveTimeout 5 # 长连接空闲超时时间(超过此时间关闭连接,单位:秒) ``` **多处理模块(MPM)配置** Apache 通过 MPM 管理进程 / 线程,处理客户端请求。apache2.conf 中通常通过 Include 指令引入 MPM 配置(不同 MPM 配置文件位于 /etc/apache2/mods-available/): ```txt # 引入 MPM 配置(根据启用的 MPM 自动加载对应配置) # 例如:prefork 对应 mpm_prefork.conf,event 对应 mpm_event.conf IncludeOptional mods-enabled/mpm*.load IncludeOptional mods-enabled/mpm*.conf ``` **目录权限控制(\<Directory> 块)** 通过 \<Directory> 块定义对特定目录的访问规则,是 Apache 权限控制的核心。apache2.conf 中包含全局目录规则,虚拟主机中可覆盖这些规则: ```txt # 根目录(/)的默认权限(严格限制,禁止访问) <Directory /> Options FollowSymLinks # 允许跟随符号链接(不允许列出目录内容) AllowOverride None # 禁止 .htaccess 文件覆盖配置 Require all denied # 拒绝所有访问(默认禁止访问系统根目录) </Directory> # 网站内容目录的权限(允许访问) <Directory /var/www/> Options Indexes FollowSymLinks # Indexes:允许列出目录内容;FollowSymLinks:允许跟随符号链接 AllowOverride None # 禁止 .htaccess 生效(如需启用,改为 All) Require all granted # 允许所有访问(允许客户端访问网站目录) </Directory> # CGI 脚本目录权限(若启用 CGI 模块) <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI # 允许执行 CGI 脚本 Require all granted </Directory> ``` 说明: - Options:控制目录行为(Indexes 允许目录浏览,FollowSymLinks 允许跟随符号链接,-Indexes 禁用目录浏览)。 - AllowOverride:是否允许 .htaccess 文件覆盖当前配置(None 禁用,All 允许所有指令,FileInfo 仅允许 URL 重写等)。 - Require:访问控制(all granted 允许所有,all denied 拒绝所有,ip 192.168.1.0/24 仅允许特定 IP 段)。 **其他核心配置** ```txt # 索引文件(访问目录时默认查找的文件,按顺序匹配) DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm # .htaccess 文件名(用户级目录配置文件,需配合 AllowOverride 使用) AccessFileName .htaccess # 禁止访问 .htaccess 和 .htpasswd 文件(避免敏感配置泄露) <FilesMatch "^\.ht"> Require all denied </FilesMatch> # 日志级别(控制错误日志的详细程度,可选:debug/info/notice/warn/error/crit/alert/emerg) LogLevel warn # 引入其他配置文件(模块化管理) Include ports.conf # 端口配置(默认 80/443 端口) IncludeOptional conf-enabled/*.conf # 启用的补充配置片段 IncludeOptional sites-enabled/*.conf # 启用的虚拟主机配置 ``` 值得注意的是:修改后必须验证配置是否正确。 ```bash apache2ctl configtest #显示 Syntax OK 表示无错误。 ``` ## 安装 ```bash # 更新系统包列表 sudo apt update # 安装Apache sudo apt install apache2 -y # 启动服务并设置开机自启 sudo systemctl start apache2 sudo systemctl enable apache2 # 验证服务状态(显示active (running)即为成功) sudo systemctl status apache2 ``` ```bash root@test-VMware-Virtual-Platform:/home/test# systemctl start apache2 root@test-VMware-Virtual-Platform:/home/test# systemctl status apache2 ● apache2.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled) Active: active (running) since Fri 2025-09-12 16:25:59 CST; 30s ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 2820 (apache2) Tasks: 55 (limit: 4540) Memory: 5.6M (peak: 6.5M) CPU: 39ms CGroup: /system.slice/apache2.service ├─2820 /usr/sbin/apache2 -k start ├─2822 /usr/sbin/apache2 -k start └─2823 /usr/sbin/apache2 -k start 9月 12 16:25:59 test-VMware-Virtual-Platform systemd[1]: Starting apache2.service - The Apache HTTP Server... 9月 12 16:25:59 test-VMware-Virtual-Platform apachectl[2819]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName'> 9月 12 16:25:59 test-VMware-Virtual-Platform systemd[1]: Started apache2.service - The Apache HTTP Server. ``` 使用浏览器访问实验机器所在的IP地址:  默认页面所在位置 /var/www/html : ```bash root@test-VMware-Virtual-Platform:/var/www/html# pwd /var/www/html root@test-VMware-Virtual-Platform:/var/www/html# cat index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <!-- Modified from the Debian original for Ubuntu Last updated: 2022-03-22 See: https://launchpad.net/bugs/1966004 --> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Apache2 Ubuntu Default Page: It works</title> ``` 默认的文件目录: ```bash root@test-VMware-Virtual-Platform:/etc/apache2# pwd /etc/apache2 root@test-VMware-Virtual-Platform:/etc/apache2# ll 总计 96 drwxr-xr-x 8 root root 4096 9月 12 16:25 ./ drwxr-xr-x 141 root root 12288 9月 12 16:26 ../ -rw-r--r-- 1 root root 7178 8月 11 19:10 apache2.conf drwxr-xr-x 2 root root 4096 9月 12 16:25 conf-available/ drwxr-xr-x 2 root root 4096 9月 12 16:25 conf-enabled/ -rw-r--r-- 1 root root 1782 3月 18 2024 envvars -rw-r--r-- 1 root root 31063 3月 18 2024 magic drwxr-xr-x 2 root root 12288 9月 12 16:25 mods-available/ drwxr-xr-x 2 root root 4096 9月 12 16:25 mods-enabled/ -rw-r--r-- 1 root root 274 3月 18 2024 ports.conf drwxr-xr-x 2 root root 4096 9月 12 16:25 sites-available/ drwxr-xr-x 2 root root 4096 9月 12 16:25 sites-enabled/ ``` 默认情况下的主配置文件内容: ```bash root@test-VMware-Virtual-Platform:/etc/apache2# cat ./apache2.conf # This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions. # See http://httpd.apache.org/docs/2.4/ for detailed information about # the directives and /usr/share/doc/apache2/README.Debian about Debian specific # hints. # # # Summary of how the Apache 2 configuration works in Debian: # The Apache 2 web server configuration in Debian is quite different to # upstream's suggested way to configure the web server. This is because Debian's # default Apache2 installation attempts to make adding and removing modules, # virtual hosts, and extra configuration directives as flexible as possible, in # order to make automating the changes and administering the server as easy as # possible. # It is split into several files forming the configuration hierarchy outlined # below, all located in the /etc/apache2/ directory: # # /etc/apache2/ # |-- apache2.conf # | `-- ports.conf # |-- mods-enabled # | |-- *.load # | `-- *.conf # |-- conf-enabled # | `-- *.conf # `-- sites-enabled # `-- *.conf # # # * apache2.conf is the main configuration file (this file). It puts the pieces # together by including all remaining configuration files when starting up the # web server. # # * ports.conf is always included from the main configuration file. It is # supposed to determine listening ports for incoming connections which can be # customized anytime. # # * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ # directories contain particular configuration snippets which manage modules, # global configuration fragments, or virtual host configurations, # respectively. # # They are activated by symlinking available configuration files from their # respective *-available/ counterparts. These should be managed by using our # helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See # their respective man pages for detailed information. # # * The binary is called apache2. Due to the use of environment variables, in # the default configuration, apache2 needs to be started/stopped with # /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not # work with the default configuration. # Global configuration # # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # NOTE! If you intend to place this on an NFS (or otherwise network) # mounted filesystem then please read the Mutex documentation (available # at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>); # you will save yourself a lot of trouble. # # Do NOT add a slash at the end of the directory path. # #ServerRoot "/etc/apache2" # # The accept serialization lock file MUST BE STORED ON A LOCAL DISK. # #Mutex file:${APACHE_LOCK_DIR} default # # The directory where shm and other runtime files will be stored. # DefaultRuntimeDir ${APACHE_RUN_DIR} # # PidFile: The file in which the server should record its process # identification number when it starts. # This needs to be set in /etc/apache2/envvars # PidFile ${APACHE_PID_FILE} # # Timeout: The number of seconds before receives and sends time out. # Timeout 300 # # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 100 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. # KeepAliveTimeout 5 # These need to be set in /etc/apache2/envvars User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP} # # HostnameLookups: Log the names of clients or just their IP addresses # e.g., www.apache.org (on) or 204.62.129.132 (off). # The default is off because it'd be overall better for the net if people # had to knowingly turn this feature on, since enabling it means that # each client request will result in AT LEAST one lookup request to the # nameserver. # HostnameLookups Off # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a <VirtualHost> # container, that host's errors will be logged there and not here. # ErrorLog ${APACHE_LOG_DIR}/error.log # # LogLevel: Control the severity of messages logged to the error_log. # Available values: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the log level for particular modules, e.g. # "LogLevel info ssl:warn" # LogLevel warn # Include module configuration: IncludeOptional mods-enabled/*.load IncludeOptional mods-enabled/*.conf # Include list of ports to listen on Include ports.conf # Sets the default security model of the Apache2 HTTPD server. It does # not allow access to the root filesystem outside of /usr/share and /var/www. # The former is used by web applications packaged in Debian, # the latter may be used for local directories served by the web server. If # your system is serving content from a sub-directory in /srv you must allow # access here, or in any related virtual host. <Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> #<Directory /srv/> # Options Indexes FollowSymLinks # AllowOverride None # Require all granted #</Directory> # AccessFileName: The name of the file to look for in each directory # for additional configuration directives. See also the AllowOverride # directive. # AccessFileName .htaccess # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <FilesMatch "^\.ht"> Require all denied </FilesMatch> # # The following directives define some format nicknames for use with # a CustomLog directive. # # These deviate from the Common Log Format definitions in that they use %O # (the actual bytes sent including headers) instead of %b (the size of the # requested file), because the latter makes it impossible to detect partial # requests. # # Note that the use of %{X-Forwarded-For}i instead of %h is not recommended. # Use mod_remoteip instead. # LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %O" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent # Include of directories ignores editors' and dpkg's backup files, # see README.Debian for details. # Include generic snippets of statements IncludeOptional conf-enabled/*.conf # Include the virtual host configurations: IncludeOptional sites-enabled/*.conf root@test-VMware-Virtual-Platform:/etc/apache2# ``` ## 卸载 首先停止apache服务: ```bash systemctl stop apache2 ``` 卸载主程序: ```bash apt remove apache2 apache2-utils apache2-bin apache2-data -y apt purge apache2 apache2-utils apache2-bin apache2-data -y ``` - `apache2`:主程序包 - `apache2-utils`:辅助工具(如`htpasswd`) - `apache2-bin`:二进制执行文件 - `apache2-data`:数据文件(如默认网页、图标等) `purge`与`remove`的区别:`purge`会删除所有配置文件(如`/etc/apache2/`目录下的`apache2.conf`、虚拟主机配置等),而`remove`仅删除程序文件,保留配置。 删除残留目录:即使执行`purge`,以下目录可能仍会保留(因包含用户数据),如需彻底清理可手动删除。 ```bash # 网站内容目录(默认存放网站文件) sudo rm -rf /var/www/ # 日志目录(存放访问日志和错误日志) sudo rm -rf /var/log/apache2/ # 配置残留目录(若purge未完全删除) sudo rm -rf /etc/apache2/ ``` 清理残留依赖: ```bash apt autoremove -y apt autoclean ``` 验证卸载结果: ```bash root@test-VMware-Virtual-Platform:/# systemctl status apache2 Unit apache2.service could not be found. root@test-VMware-Virtual-Platform:/# which apache2 root@test-VMware-Virtual-Platform:/# ```
毛林
2025年9月12日 20:36
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文档(打印)
分享
链接
类型
密码
更新密码