debian

如何在Debian Apache2中提高网站速度

小樊
40
2025-11-20 06:32:19
栏目: 云计算

Debian Apache2 网站提速实操清单

一 基础优化

# 启用压缩
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json application/x-javascript
</IfModule>

# 启用浏览器缓存
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/html "access plus 1 hour"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
</IfModule>

# 开启 KeepAlive
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

# 精简访问日志(按需)
# CustomLog ${APACHE_LOG_DIR}/access.log common
LogLevel warn

完成后执行:sudo systemctl restart apache2 使配置生效。

二 并发与 MPM 调优

<IfModule mpm_event_module>
    StartServers             2
    MinSpareThreads         25
    MaxSpareThreads         75
    ThreadLimit             64
    ThreadsPerChild         25
    MaxRequestWorkers       150
    MaxConnectionsPerChild   0
</IfModule>

三 启用 HTTP/2 与 TLS 优化

SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"
SSLUseStapling On
SSLStaplingCache "shmcb:/var/run/stapling-cache(150000)"

SSLSessionCache "shmcb:/var/run/ssl_scache(512000)"
SSLSessionCacheTimeout 300

四 页面与后端加速

zend_extension = opcache.so
opcache.enable = 1
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 60
opcache.fast_shutdown = 1

五 验证与持续监控

0
看了该问题的人还看了