首页 帮助中心 帮助中心 美国高防云服务器安装Apache教程
美国高防云服务器安装Apache教程
时间 : 2025-03-06 17:17:53 编辑 : 华纳云 阅读量 : 30

  美国高防云服务器安装Apache的步骤在Linux大多数发行版本中是比较类似的,有的用户可能习惯用Ubuntu系统,有的用户可能习惯centos系统,我们将给出Ubuntu操作系统的安装命令,这个教程很详细但不过于基础,同时也涵盖了一些必要的安全措施。

  在进行安装Apache之前,需要用户登录到自己的服务器,并进行系统的更新,以免出现版本非最新版出现安装错误等问题。

  登录服务器命令:

  ssh root@your_server_ip # 替换为你的服务器IP

  更新系统命令:

  apt update && apt upgrade -y # Ubuntu/Debian
  # 或
  yum update -y # CentOS/RHEL

  在完成上述的操作后,我们需要安装Apache,具体命令如下:

  apt install apache2 -y
  systemctl start apache2
  systemctl enable apache2

  验证安装,访问 http://your_server_ip,若看到 Apache 默认页面即成功

  配置防火墙:

  ufw allow 80/tcp # 开放 HTTP
  ufw allow 443/tcp # 开放 HTTPS
  ufw reload

  美国高防云服务器可能需要额外配置,确保高防策略允许80/443端口流量,同时还建议限制SSH端口,比如22端口,仅允许可信的IP进行访问。

  Apache 基础安全配置:

  禁用不必要的模块:

  # Ubuntu/Debian
  a2dismod autoindex status    # 禁用目录列表和状态模块
  # CentOS
  vim /etc/httpd/conf.modules.d/00-base.conf  # 注释不需要的模块
  systemctl restart apache2/httpd

  配置虚拟主机:

  vim /etc/apache2/sites-available/your_domain.conf  # Ubuntu
  # 或
  vim /etc/httpd/conf.d/your_domain.conf             # CentOS
<VirtualHost *:80>
    ServerName your_domain.com
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options -Indexes +FollowSymLinks  # 禁用目录列表
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
  a2ensite your_domain.conf  # Ubuntu
  systemctl restart apache2

  设置目录权限:

  chown -R www-data:www-data /var/www/html  # Ubuntu
  chown -R apache:apache /var/www/html      # CentOS
  chmod 755 -R /var/www/html

 启用 HTTPS (SSL),我们可以通过安装Certbot 获取 Let's Encrypt 证书

# Ubuntu
apt install certbot python3-certbot-apache -y
certbot --apache -d your_domain.com

# CentOS
yum install epel-release -y
yum install certbot python3-certbot-apache -y
certbot --apache -d your_domain.com

  自动续签证书

echo "0 0 * * * /usr/bin/certbot renew --quiet" | crontab -

  Apache 层可以进行以下设置来防 DDoS/CC 攻击配置

  安装 mod_evasive (防暴力请求)

# Ubuntu
apt install libapache2-mod-evasive
# CentOS
yum install mod_evasive

# 配置
vim /etc/apache2/mods-available/evasive.conf  # Ubuntu
# 或
vim /etc/httpd/conf.d/mod_evasive.conf        # CentOS
<IfModule mod_evasive20.c>
    DOSHashTableSize 3097
    DOSPageCount 2         # 单页面每秒最大请求数
    DOSSiteCount 50        # 全站每秒最大请求数
    DOSPageInterval 1      # 计数时间间隔(秒)
    DOSSiteInterval 1
    DOSBlockingPeriod 10   # 封锁时间(秒)
</IfModule>

  重启 Apache 生效。

  调整 timeout 参数

# 在 Apache 主配置中增加
Timeout 60                 # 减少超时时间(默认300秒)
KeepAliveTimeout 5         # 限制Keep-Alive

  当然,在美国高防云服务器上安装Apache还有一些注意事项,你需要使用apt upgrade 或 yum update命令来保持系统和Apache的版本是最新版本,然后还要注意的一点就是在修改关键配置之前都要做好备份文件,以免操作不当导致严重的问题出现。通过上述的步骤,你可以成功的在美国高防云上安全的部署Apache。

华纳云 推荐文章
美国高防云服务器配置FTP步骤(以centos系统为例) 如何在美国高防云服务器上面配置IPV6地址 美国高防云服务器部署Nginx的详细步骤 如何在美国高防云服务器设置访问控制规则 如何在CentOS中安装ApacheWeb服务器? Ubuntu下如何安装apache2服务器 Ubuntu如何安装apache2服务器 Ubuntu系统安装apache ant教程
客服咨询
7*24小时技术支持
技术支持
渠道支持