You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu部署Apache2服务器遇异常:127.0.1.1无法访问及配置提示

问题解决步骤

1. 修正虚拟主机配置的错误

你的虚拟主机配置存在两处明显问题:

  • 示例行ServerName www.example.com末尾多了一个多余的反引号`,会导致Apache解析配置失败
  • 同一个<VirtualHost *:80>块里重复定义了ServerName,虽然Apache会以最后一个为准,但这种写法属于不良配置,建议直接注释或删除无用的示例行

另外,要让127.0.1.1能正常访问,需将该IP添加到虚拟主机的ServerAlias中。修改后的完整配置如下:

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
# ServerName www.example.com  # 注释或删除该行示例配置

ServerAdmin myemail@gmail.com
ServerName mydomain.com
ServerAlias server.mydomain.com 127.0.1.1  # 新增127.0.1.1作为访问别名
DocumentRoot /media/balkanflix/SERIJALI/Balkanflix

<Directory /media/balkanflix/SERIJALI/Balkanflix>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

2. 解决全局ServerName缺失的问题

执行sudo apachectl configtest时出现的AH00558提示,是因为Apache无法自动识别服务器的完全限定域名,需要在全局配置中添加ServerName指令:

  • 打开Apache全局配置文件:/etc/apache2/apache2.conf
  • 在文件末尾添加一行:
ServerName 127.0.1.1

如果你的域名已指向该服务器,也可以填写域名mydomain.com

3. 验证配置并重启服务

修改完成后,先执行配置检测确认语法正确:

sudo apachectl configtest

当返回Syntax OK时,重启Apache服务:

sudo systemctl restart apache2

4. 测试访问

此时再访问http://127.0.1.1/,即可正常加载你的动漫流媒体网站内容。

问题根源说明

静态IP 192.168.1.100能正常访问,是因为Apache会默认匹配第一个符合<VirtualHost *:80>规则的虚拟主机;而127.0.1.1未被配置在虚拟主机的ServerName或ServerAlias中,Apache找不到对应的主机配置,因此返回无法访问。

内容的提问来源于stack exchange,提问作者Strahinja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 20:56:20