用 Apache2 打造更快、更可信、更易被发现的网站,从而放大品牌影响力
一 核心思路与衡量指标
二 性能与稳定性优化
sudo a2enmod http2 && sudo systemctl restart apache2sudo a2enmod headers && sudo a2enmod deflate<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json
</IfModule>
sudo a2enmod expires<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
</IfModule>
KeepAlive On、MaxKeepAliveRequests 100–200、KeepAliveTimeout 5–10StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 0
<IfModule mod_cache.c>
<IfModule mod_cache_disk.c>
CacheRoot /var/cache/apache2/mod_cache_disk
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
</IfModule>
</IfModule>
Header set Cache-Control "max-age=3600, public"
三 安全与信任建设
sudo apt install certbot python3-certbot-apache && sudo certbot --apache -d yourdomain.com -d www.yourdomain.comSSLEngine on,并添加安全头:Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "no-referrer-when-downgrade"
ServerSignature Off、ServerTokens Prod、Options -IndexesRequire all granted/Require ip 1.2.3.4,并可限制方法:LimitExcept GET POSTsudo ufw allow 'Apache Full'fail2ban 监控日志并封禁暴力尝试四 SEO 与内容可见度
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
User-agent: *;Disallow: /private/;Allow: /public/五 可观测性、扩展与上线清单
CustomLog ${APACHE_LOG_DIR}/access.log combined、LogLevel warnGoAccess 生成可视化报告;监控告警:Prometheus + Grafana 观测 TTFB、5xx、QPS、CPU/内存。mod_proxy、mod_proxy_http<VirtualHost *:80>
ServerName service.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>