1. 安装Apache
  • Ubuntu/Debiansudo apt-get install apache2
  • CentOS/Fedorasudo yum install httpd
  • Windows: 下载Apache二进制文件并解压到指定目录。
  1. 启动Apache
  • Ubuntu/Debiansudo systemctl start apache2
  • CentOS/Fedorasudo systemctl start httpd
  • Windows: 在命令行中进入Apache的bin目录,运行httpd.exe
  1. 配置Apache
  • Ubuntu/Debiansudo systemctl restart apache2
  • CentOS/Fedorasudo systemctl restart httpd
  • Windows: 停止并重新启动httpd.exe
  • 主配置文件通常位于/etc/apache2/apache2.conf(Ubuntu/Debian)或/etc/httpd/conf/httpd.conf(CentOS/Fedora)。
  • 修改配置文件后,重启Apache服务以应用更改:
  1. 设置虚拟主机
  • Ubuntu/Debiansudo a2ensite your-site.conf
  • CentOS/Fedora: 直接在httpd.conf中配置。
  • 在配置文件中添加<VirtualHost>块来定义虚拟主机。
  • 确保启用虚拟主机配置文件:
  1. 测试配置
  • 在浏览器中输入服务器IP地址或域名,查看是否显示Apache默认页面。
  • 使用apachectl configtest或httpd -t命令检查配置文件语法是否正确。
  1. 防火墙设置
  • Ubuntu/Debian: sudo ufw allow 'Apache Full'
  • CentOS/Fedora: sudo firewall-cmd --permanent --add-service=http --add-service=https,然后sudo firewall-cmd --reload。
  • 确保防火墙允许HTTP(端口80)和HTTPS(端口443)流量:
  1. 启用Apache开机启动
  • Ubuntu/Debian: sudo systemctl enable apache2
  • CentOS/Fedora: sudo systemctl enable httpd
  • Windows: 将Apache服务添加到系统服务中。