Apache作为全球使用最广泛的Web服务器软件,在Linux系统中占据着重要地位。本文将详细介绍在主流Linux发行版(CentOS/Ubuntu)上配置Apache服务器的完整流程,包含从安装到优化的全步骤。
sudo yum install httpdsudo apt-get install apache2安装完成后,通过以下命令检查版本:apache2 -v 或 httpd -v
/etc/httpd/conf/httpd.conf(CentOS)/etc/apache2/apache2.conf(Ubuntu)/etc/apache2/sites-available/ServerRoot "/etc/apache2"
Listen 80
ServerAdmin webmaster@example.com
DocumentRoot "/var/www/html"
示例配置(保存为/etc/apache2/sites-available/example.com.conf):
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
sudo a2ensite example.com.conf
sudo systemctl reload apache2
Options -IndexesServerTokens Prod
ServerSignature Offsudo ufw allow 'Apache Full'启用常用模块:sudo a2enmod rewrite
sudo a2enmod expires
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
apachectl configtestnetstat -tulnp检查端口占用通过本文的详细指导,您应该已经掌握了在Linux系统上配置Apache服务器的完整流程。建议定期检查官方文档获取最新安全更新信息,保持服务器的最佳状态。
公司已全面启动企业微信客户服务,请优先选择微信客服进行咨询。