帮助中心

如果没有找到您需要的问题,随时联系我们

Apache服务器配置指南

2025-12-21 云服务器帮助

Apache是世界上使用最广泛的Web服务器软件。

安装Apache:

CentOS:
yum install httpd -y
systemctl start httpd
systemctl enable httpd

Ubuntu:
apt install apache2 -y
systemctl start apache2

配置文件位置:

  • CentOS: /etc/httpd/conf/httpd.conf
  • Ubuntu: /etc/apache2/apache2.conf

虚拟主机配置:

<VirtualHost *:80>
  ServerName www.example.com
  ServerAlias example.com
  DocumentRoot /var/www/example

  <Directory /var/www/example>
    AllowOverride All
    Require all granted
  </Directory>

  ErrorLog /var/log/httpd/example-error.log
  CustomLog /var/log/httpd/example-access.log combined
</VirtualHost>

启用mod_rewrite:

  • CentOS: 默认启用
  • Ubuntu: a2enmod rewrite

.htaccess启用:

在Directory配置中设置:
AllowOverride All

常用模块:

  • mod_rewrite - URL重写
  • mod_ssl - HTTPS支持
  • mod_headers - 自定义头部
  • mod_expires - 缓存控制

检查配置:

apachectl configtest

重启服务:

systemctl restart httpd

返回列表

相关文章

定时任务Crontab使用教程
Docker容器入门教程
SSH密钥登录配置教程
服务器性能监控指南
Telegram