参考资料

  1. apache安装与配置windows
  2. apache安装与配置idea
  3. apache安装与配置 qgis
  4. apache和tomcat区别
  5. apache安装与配置端口占用
  6. apache安装与配置windows
  7. apache安装与配置 linux
  8. apache是干嘛用的
  1. 安装Apache

    • Ubuntu/Debian: sudo apt-get install apache2

    • CentOS/Fedora: sudo yum install httpd

    • Windows: 下载Apache二进制文件并解压到指定目录。

  2. 启动Apache

    • Ubuntu/Debian: sudo systemctl start apache2

    • CentOS/Fedora: sudo systemctl start httpd

    • Windows: 在命令行中进入Apache的bin目录,运行httpd.exe

  3. 配置Apache

    • Ubuntu/Debian: sudo systemctl restart apache2

    • CentOS/Fedora: sudo systemctl restart httpd

    • Windows: 停止并重新启动httpd.exe

    • 主配置文件通常位于/etc/apache2/apache2.conf(Ubuntu/Debian)或/etc/httpd/conf/httpd.conf(CentOS/Fedora)。

    • 修改配置文件后,重启Apache服务以应用更改:

  4. 设置虚拟主机

    • Ubuntu/Debian: sudo a2ensite your-site.conf

    • CentOS/Fedora: 直接在httpd.conf中配置。

    • 在配置文件中添加<VirtualHost>块来定义虚拟主机。

    • 确保启用虚拟主机配置文件:

  5. 测试配置

    • 在浏览器中输入服务器IP地址或域名,查看是否显示Apache默认页面。

    • 使用apachectl configtesthttpd -t命令检查配置文件语法是否正确。

  6. 防火墙设置

    • 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)流量:

  7. 启用Apache开机启动

    • Ubuntu/Debian: sudo systemctl enable apache2

    • CentOS/Fedora: sudo systemctl enable httpd

    • Windows: 将Apache服务添加到系统服务中。