1. Apache HTTP Server简介与版本说明
Apache HTTP Server(简称Apache)是Apache软件基金会的一个开源网页服务器软件,是世界上使用最广泛的Web服务器软件之一。更多学习教程www.fgedu.net.cn。Apache以其稳定性、安全性和丰富的功能而闻名,支持多种操作系统平台。
Apache采用模块化设计,可以通过加载不同的模块来扩展功能,如SSL加密、URL重写、代理服务等。学习交流加群风哥微信: itpux-com。Apache支持CGI、FastCGI、PHP、Python等多种动态内容处理方式,是企业级Web应用的首选服务器之一。
Apache核心特性:
– 虚拟主机:支持基于IP、端口和域名的虚拟主机
– SSL/TLS:支持HTTPS加密传输
– URL重写:强大的mod_rewrite模块
– 代理服务:支持正向代理和反向代理
– 认证授权:多种认证方式支持
– 日志管理:灵活的日志配置
– 动态内容:支持CGI、FastCGI、PHP等
– 负载均衡:支持mod_proxy_balancer
– 缓存功能:支持mod_cache缓存
– 压缩传输:支持gzip压缩
– WebDAV:支持WebDAV协议
Apache与其他Web服务器对比:
配置复杂度 中等 中等 简单
模块化 丰富 中等 中等
动态内容 优秀 良好 良好
静态内容 良好 优秀 优秀
内存占用 中等 低 低
学习曲线 中等 陡峭 平缓
企业支持 广泛 广泛 有限
文档完善度 优秀 优秀 良好
2. Apache版本选择与下载地址
Apache HTTP Server当前主要维护2.4.x系列,采用语义化版本号。
Apache版本状态:
2.4.66 2025-12-04 最新稳定版
2.4.65 2025-XX-XX 稳定版
2.4.64 2025-XX-XX 稳定版
2.4.63 2025-XX-XX 维护版
2.4.62 2025-XX-XX 维护版
Apache 2.4.66主要更新:
– 安全漏洞修复
– 性能优化
– Bug修复
– 模块更新
– 兼容性改进
官方下载地址:
下载页面:https://httpd.apache.org/download.cgi
源码仓库:https://github.com/apache/httpd
文档中心:https://httpd.apache.org/docs/2.4/
模块仓库:https://modules.apache.org/
3. Apache下载方式详解
方式一:源码编译安装(推荐生产环境)
$ cd /fgeudb/software
$ wget https://dlcdn.apache.org/httpd/httpd-2.4.66.tar.bz2
输出示例如下:
–2026-04-04 10:00:00– https://dlcdn.apache.org/httpd/httpd-2.4.66.tar.bz2
Resolving dlcdn.apache.org… 151.101.2.132
Connecting to dlcdn.apache.org|151.101.2.132|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 7234567 (6.9M) [application/octet-stream]
Saving to: ‘httpd-2.4.66.tar.bz2’
httpd-2.4.66.tar.bz2 100%[======================================================================>] 6.90M 5.8MB/s in 1.2s
2026-04-04 10:00:02 (5.8 MB/s) – ‘httpd-2.4.66.tar.bz2’ saved [7234567/7234567]
下载依赖库APR和APR-util:
$ wget https://dlcdn.apache.org/apr/apr-1.7.5.tar.gz
$ wget https://dlcdn.apache.org/apr/apr-util-1.6.3.tar.gz
解压源码包:
$ tar -jxvf httpd-2.4.66.tar.bz2 -C /fgeudb/
$ tar -zxvf apr-1.7.5.tar.gz -C /fgeudb/httpd-2.4.66/srclib/ –strip-components=1 –transform ‘s,apr-1.7.5,apr,’
$ tar -zxvf apr-util-1.6.3.tar.gz -C /fgeudb/httpd-2.4.66/srclib/ –strip-components=1 –transform ‘s,apr-util-1.6.3,apr-util,’
安装编译依赖:
# yum install -y gcc pcre-devel zlib-devel openssl-devel expat-devel libxml2-devel
或Ubuntu/Debian:
# apt install -y build-essential libpcre3-dev zlib1g-dev libssl-dev libexpat1-dev libxml2-dev
方式二:包管理器安装
# yum install -y httpd httpd-devel
输出示例如下:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.4.66-1.el7 will be installed
—> Package httpd-devel.x86_64 0:2.4.66-1.el7 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.66-1.el7 base 1.2 M
httpd-devel x86_64 2.4.66-1.el7 base 250 k
Transaction Summary
================================================================================
Install 2 Packages
Total download size: 1.5 M
Installed size: 4.5 M
Downloading packages:
——————————————————————————–
Total 2.5 MB/s | 1.5 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : httpd-2.4.66-1.el7.x86_64 1/2
Installing : httpd-devel-2.4.66-1.el7.x86_64 2/2
Verifying : httpd-devel-2.4.66-1.el7.x86_64 1/2
Verifying : httpd-2.4.66-1.el7.x86_64 2/2
Installed:
httpd.x86_64 0:2.4.66-1.el7 httpd-devel.x86_64 0:2.4.66-1.el7
Complete!
Ubuntu/Debian安装:
# apt update
# apt install -y apache2 apache2-dev
输出示例如下:
Reading package lists… Done
Building dependency tree… Done
The following NEW packages will be installed:
apache2 apache2-dev
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,234 kB of archives.
After this operation, 4,567 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 apache2 amd64 2.4.66-1 [1,100 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 apache2-dev amd64 2.4.66-1 [134 kB]
Fetched 1,234 kB in 2s (617 kB/s)
Selecting previously unselected package apache2…
(Reading database … 123456 files and directories currently installed.)
Preparing to unpack …/apache2_2.4.66-1_amd64.deb …
Unpacking apache2 (2.4.66-1) …
Setting up apache2 (2.4.66-1) …
验证安装:
$ httpd -v
输出示例如下:
Server version: Apache/2.4.66 (Unix)
Server built: Apr 4 2026 10:00:00
方式三:Docker容器部署
$ docker pull httpd:2.4.66
输出示例如下:
2.4.66: Pulling from library/httpd
Digest: sha256:abc123def456…
Status: Downloaded newer image for httpd:2.4.66
启动Apache容器:
$ docker run –name apache-web \
-p 80:80 \
-p 443:443 \
-v /fgeudb/apache/conf:/usr/local/apache2/conf:ro \
-v /fgeudb/apache/htdocs:/usr/local/apache2/htdocs:ro \
-v /fgeudb/apache/logs:/usr/local/apache2/logs \
-d httpd:2.4.66
输出示例如下:
abc123def456789…
查看容器状态:
$ docker ps | grep httpd
输出示例如下:
abc123def456 httpd:2.4.66 “httpd-foreground” 10 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp apache-web
4. Apache安装部署实战
步骤1:编译安装Apache
# groupadd apache
# useradd -g apache -s /sbin/nologin -M apache
配置编译选项:
$ cd /fgeudb/httpd-2.4.66
$ ./configure \
–prefix=/fgeudb/apache \
–enable-so \
–enable-ssl \
–enable-cgi \
–enable-rewrite \
–enable-mods-shared=most \
–enable-mpms-shared=all \
–with-mpm=event \
–with-included-apr \
–enable-proxy \
–enable-proxy-http \
–enable-proxy-balancer \
–enable-cache \
–enable-disk-cache \
–enable-deflate \
–enable-expires \
–enable-headers \
–enable-modules=all
输出示例如下:
checking for chosen layout… Apache
checking for working mkdir -p… yes
checking for grep that handles long lines and -e… /usr/bin/grep
checking for egrep… /usr/bin/grep -E
…
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
编译安装:
$ make -j$(nproc)
# make install
输出示例如下:
Making all in srclib
make[1]: Entering directory ‘/fgeudb/httpd-2.4.66/srclib’
…
Installing configuration files
mkdir /fgeudb/apache/conf
步骤2:创建目录结构
# mkdir -p /fgeudb/apache/{conf/extra,htdocs,logs,modules}
# chown -R apache:apache /fgeudb/apache
# chmod -R 755 /fgeudb/apache
创建测试页面:
# echo “<html><body><h1>Welcome to Apache!</h1></body></html>” > /fgeudb/apache/htdocs/index.html
步骤3:配置systemd服务
# vi /etc/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=https://httpd.apache.org/docs/2.4/
[Service]
Type=forking
EnvironmentFile=/fgeudb/apache/conf/envvars
ExecStart=/fgeudb/apache/bin/apachectl start
ExecStop=/fgeudb/apache/bin/apachectl stop
ExecReload=/fgeudb/apache/bin/apachectl graceful
PrivateTmp=true
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
创建环境变量文件:
# vi /fgeudb/apache/conf/envvars
HTTPD_ROOT=/fgeudb/apache
HTTPD=/fgeudb/apache/bin/httpd
PIDFILE=/fgeudb/apache/logs/httpd.pid
重载服务配置:
# systemctl daemon-reload
启动服务:
# systemctl start httpd
设置开机自启:
# systemctl enable httpd
查看服务状态:
# systemctl status httpd
输出示例如下:
● httpd.service – The Apache HTTP Server
Loaded: loaded (/etc/systemd/system/httpd.service; enabled)
Active: active (running) since Fri 2026-04-04 10:05:00 CST; 10s ago
Process: 12345 ExecStart=/fgeudb/apache/bin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 12346 (httpd)
CGroup: /system.slice/httpd.service
├─12346 /fgeudb/apache/bin/httpd -k start
├─12347 /fgeudb/apache/bin/httpd -k start
└─12348 /fgeudb/apache/bin/httpd -k start
5. Apache配置文件详解
步骤1:创建主配置文件
# vi /fgeudb/apache/conf/httpd.conf
ServerRoot “/fgeudb/apache”
ServerName www.fgedu.net.cn:80
ServerAdmin webmaster@fgedu.net.cn
ServerSignature Off
ServerTokens Prod
Listen 80
Listen 443 https
User apache
Group apache
DocumentRoot “/fgeudb/apache/htdocs”
DirectoryIndex index.html index.htm index.php
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule expires_module modules/mod_expires.so
LoadModule cache_module modules/mod_cache.so
LoadModule cache_disk_module modules/mod_cache_disk.so
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory “/fgeudb/apache/htdocs”>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
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
CustomLog “logs/access_log” combined
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
步骤2:配置MPM模块
<IfModule mpm_event_module>
StartServers 4
ServerLimit 16
ThreadLimit 64
ThreadsPerChild 64
MinSpareThreads 64
MaxSpareThreads 192
MaxRequestWorkers 1024
MaxConnectionsPerChild 10000
</IfModule>
Prefork MPM配置(兼容模式):
<IfModule mpm_prefork_module>
StartServers 8
MinSpareServers 8
MaxSpareServers 20
ServerLimit 256
MaxRequestWorkers 256
MaxConnectionsPerChild 10000
</IfModule>
Worker MPM配置:
<IfModule mpm_worker_module>
StartServers 4
ServerLimit 16
ThreadLimit 64
ThreadsPerChild 64
MinSpareThreads 64
MaxSpareThreads 192
MaxRequestWorkers 1024
MaxConnectionsPerChild 10000
</IfModule>
步骤3:配置压缩和缓存
<IfModule mod_deflate.c>
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilterByType DEFLATE text/css text/javascript
AddOutputFilterByType DEFLATE application/json application/javascript
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
配置Expires缓存:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html “access plus 1 hour”
ExpiresByType text/css “access plus 7 days”
ExpiresByType text/javascript “access plus 7 days”
ExpiresByType application/javascript “access plus 7 days”
ExpiresByType image/gif “access plus 30 days”
ExpiresByType image/jpeg “access plus 30 days”
ExpiresByType image/png “access plus 30 days”
ExpiresByType image/svg+xml “access plus 30 days”
ExpiresByType application/pdf “access plus 30 days”
</IfModule>
配置Cache缓存:
<IfModule mod_cache.c>
CacheQuickHandler off
CacheLock on
CacheLockPath /tmp/cachelock
CacheLockMaxAge 5
CacheIgnoreHeaders Set-Cookie
</IfModule>
<IfModule mod_cache_disk.c>
CacheRoot /fgeudb/apache/cache
CacheDirLevels 2
CacheDirLength 1
CacheMaxFileSize 10000000
CacheMaxExpire 86400
</IfModule>
6. Apache虚拟主机配置
步骤1:配置基于域名的虚拟主机
# vi /fgeudb/apache/conf/extra/httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@fgedu.net.cn
DocumentRoot “/fgeudb/apache/htdocs/fgedu”
ServerName www.fgedu.net.cn
ServerAlias fgedu.net.cn
ErrorLog “logs/fgedu-error.log”
CustomLog “logs/fgedu-access.log” combined
<Directory “/fgeudb/apache/htdocs/fgedu”>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@fgedu.net.cn
DocumentRoot “/fgeudb/apache/htdocs/api”
ServerName api.fgedu.net.cn
ErrorLog “logs/api-error.log”
CustomLog “logs/api-access.log” combined
<Directory “/fgeudb/apache/htdocs/api”>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
在主配置中包含:
Include conf/extra/httpd-vhosts.conf
步骤2:配置基于端口的虚拟主机
Listen 8081
<VirtualHost *:8080>
ServerName www.fgedu.net.cn
DocumentRoot “/fgeudb/apache/htdocs/test1”
ErrorLog “logs/test1-error.log”
</VirtualHost>
<VirtualHost *:8081>
ServerName www.fgedu.net.cn
DocumentRoot “/fgeudb/apache/htdocs/test2”
ErrorLog “logs/test2-error.log”
</VirtualHost>
步骤3:配置反向代理
<VirtualHost *:80>
ServerName api.fgedu.net.cn
ProxyPreserveHost On
ProxyPass / http://192.168.1.51:8080/
ProxyPassReverse / http://192.168.1.51:8080/
ErrorLog “logs/proxy-error.log”
CustomLog “logs/proxy-access.log” combined
</VirtualHost>
负载均衡配置:
<Proxy “balancer://mycluster”>
BalancerMember “http://192.168.1.51:8080” loadfactor=3
BalancerMember “http://192.168.1.52:8080” loadfactor=2
BalancerMember “http://192.168.1.53:8080” loadfactor=1
ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
ServerName api.fgedu.net.cn
ProxyPreserveHost On
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
</VirtualHost>
7. Apache SSL/HTTPS配置
步骤1:生成SSL证书
$ mkdir -p /fgeudb/apache/ssl
$ openssl genrsa -out /fgeudb/apache/ssl/fgedu.key 2048
$ openssl req -new -key /fgeudb/apache/ssl/fgedu.key -out /fgeudb/apache/ssl/fgedu.csr \
-subj “/C=CN/ST=Beijing/L=Beijing/O=/CN=fgedu.net.cn”
$ openssl x509 -req -days 365 -in /fgeudb/apache/ssl/fgedu.csr \
-signkey /fgeudb/apache/ssl/fgedu.key -out /fgeudb/apache/ssl/fgedu.crt
输出示例如下:
Signature ok
subject=C=CN, ST=Beijing, L=Beijing, O=, CN=fgedu.net.cn
Getting Private key
设置权限:
# chmod 600 /fgeudb/apache/ssl/fgedu.key
步骤2:配置HTTPS虚拟主机
# vi /fgeudb/apache/conf/extra/httpd-ssl.conf
Listen 443 https
<VirtualHost *:443>
ServerName www.fgedu.net.cn
ServerAdmin webmaster@fgedu.net.cn
DocumentRoot “/fgeudb/apache/htdocs”
SSLEngine on
SSLCertificateFile “/fgeudb/apache/ssl/fgedu.crt”
SSLCertificateKeyFile “/fgeudb/apache/ssl/fgedu.key”
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder on
SSLCompression off
SSLSessionTickets off
Header always set Strict-Transport-Security “max-age=31536000; includeSubDomains”
ErrorLog “logs/ssl-error.log”
CustomLog “logs/ssl-access.log” combined
</VirtualHost>
在主配置中包含:
Include conf/extra/httpd-ssl.conf
步骤3:HTTP到HTTPS重定向
<VirtualHost *:80>
ServerName www.fgedu.net.cn
ServerAlias fgedu.net.cn
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
或使用Redirect:
<VirtualHost *:80>
ServerName www.fgedu.net.cn
Redirect permanent / https://www.fgedu.net.cn/
</VirtualHost>
8. 安装验证与测试
查看Apache状态
$ ps -ef | grep httpd
输出示例如下:
root 12345 1 0 10:05 ? 00:00:00 /fgeudb/apache/bin/httpd -k start
apache 12346 12345 0 10:05 ? 00:00:00 /fgeudb/apache/bin/httpd -k start
apache 12347 12345 0 10:05 ? 00:00:00 /fgeudb/apache/bin/httpd -k start
apache 12348 12345 0 10:05 ? 00:00:00 /fgeudb/apache/bin/httpd -k start
查看端口监听:
$ netstat -tlnp | grep httpd
输出示例如下:
tcp6 0 0 :::80 :::* LISTEN 12345/httpd
tcp6 0 0 :::443 :::* LISTEN 12345/httpd
查看Apache版本:
$ httpd -v
输出示例如下:
Server version: Apache/2.4.66 (Unix)
Server built: Apr 4 2026 10:00:00
查看编译参数:
$ httpd -V
输出示例如下:
Server version: Apache/2.4.66 (Unix)
Server built: Apr 4 2026 10:00:00
Server’s Module Magic Number: 20120211:XX
Server loaded: APR 1.7.5, APR-UTIL 1.6.3
Compiled using: APR 1.7.5, APR-UTIL 1.6.3
Architecture: 64-bit
Server MPM: event
threaded: yes (fixed thread count)
forked: yes (variable process count)
Server compiled with….
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT=”/fgeudb/apache”
-D SUEXEC_BIN=”/fgeudb/apache/bin/suexec”
-D DEFAULT_PIDLOG=”logs/httpd.pid”
-D DEFAULT_SCOREBOARD=”logs/apache_runtime_status”
-D DEFAULT_ERRORLOG=”logs/error_log”
-D AP_TYPES_CONFIG_FILE=”conf/mime.types”
-D SERVER_CONFIG_FILE=”conf/httpd.conf”
验证配置文件:
$ httpd -t
输出示例如下:
Syntax OK
访问测试
$ curl -I http://192.168.1.51
输出示例如下:
HTTP/1.1 200 OK
Date: Fri, 04 Apr 2026 10:10:00 GMT
Server: Apache
Last-Modified: Fri, 04 Apr 2026 10:05:00 GMT
ETag: “123-567890-abcdef”
Accept-Ranges: bytes
Content-Length: 1234
Content-Type: text/html
测试HTTPS访问:
$ curl -I -k https://192.168.1.51
输出示例如下:
HTTP/1.1 200 OK
Date: Fri, 04 Apr 2026 10:10:00 GMT
Server: Apache
Strict-Transport-Security: max-age=31536000; includeSubDomains
Content-Length: 1234
Content-Type: text/html
测试虚拟主机:
$ curl -I -H “Host: www.fgedu.net.cn” http://192.168.1.51
输出示例如下:
HTTP/1.1 200 OK
Date: Fri, 04 Apr 2026 10:10:00 GMT
Server: Apache
Content-Type: text/html
性能测试
$ ab -n 10000 -c 100 http://192.168.1.51/
输出示例如下:
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
…
Complete requests: 10000
Failed requests: 0
Total transferred: 12340000 bytes
HTML transferred: 6170000 bytes
Requests per second: 25678.45 [#/sec] (mean)
Time per request: 3.894 [ms] (mean)
Time per request: 0.039 [ms] (mean, across all concurrent requests)
Transfer rate: 3098.56 [Kbytes/sec] received
使用wrk进行压力测试:
$ wrk -t4 -c100 -d30s http://192.168.1.51/
输出示例如下:
Running 30s test @ http://192.168.1.51/
4 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 3.92ms 1.25ms 28.34ms 82.45%
Req/Sec 6.52k 456.78 8.23k 73.50%
778456 requests in 30.02s, 1.12GB read
Requests/sec: 25932.12
Transfer/sec: 38.12MB
9. 常见问题与解决方案
问题1:端口被占用
解决方案:
1. 查看端口占用:
$ netstat -tlnp | grep :80
2. 停止占用端口的进程:
# kill -9 $(lsof -t -i:80)
3. 或修改Apache监听端口:
Listen 8080
问题2:权限不足
解决方案:
1. 检查文件权限:
$ ls -la /fgeudb/apache/
2. 修改目录所有者:
# chown -R apache:apache /fgeudb/apache
3. 检查SELinux:
# getenforce
# setenforce 0
4. 检查目录权限:
# chmod 755 /fgeudb/apache/htdocs
问题3:模块加载失败
解决方案:
1. 检查模块是否存在:
$ ls -la /fgeudb/apache/modules/
2. 检查模块依赖:
$ ldd /fgeudb/apache/modules/mod_ssl.so
3. 安装缺失依赖:
# yum install -y openssl-devel
4. 重新编译模块:
$ ./configure –enable-ssl –enable-so
$ make
# make install
问题4:配置语法错误
解决方案:
1. 验证配置文件:
$ httpd -t
2. 检查常见语法错误:
– 标签未正确闭合
– 指令拼写错误
– 路径不存在
– 模块未加载
3. 查看详细错误:
$ httpd -t -D DUMP_VHOSTS
4. 检查模块是否加载:
$ httpd -M
Apache服务管理命令
# systemctl start httpd
或
$ /fgeudb/apache/bin/apachectl start
停止服务:
# systemctl stop httpd
或
$ /fgeudb/apache/bin/apachectl stop
优雅重启:
# systemctl reload httpd
或
$ /fgeudb/apache/bin/apachectl graceful
强制重启:
$ /fgeudb/apache/bin/apachectl restart
测试配置:
$ httpd -t
$ /fgeudb/apache/bin/apachectl configtest
查看版本:
$ httpd -v
查看已加载模块:
$ httpd -M
查看帮助:
$ httpd -h
$ /fgeudb/apache/bin/apachectl -h
1. 使用Apache 2.4.66最新稳定版本;2. 使用Event MPM提升并发性能;3. 配置systemd服务实现自动重启;4. 启用压缩减少传输流量;5. 配置SSL/HTTPS加密传输;6. 使用虚拟主机隔离不同站点;7. 配置合理的MPM参数;8. 启用缓存提升响应速度;9. 定期更新版本修复安全漏洞;10. 配置完善的日志记录和监控。
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
