AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 710984
Accepted
Zereges
Zereges
Asked: 2015-08-06 02:35:08 +0800 CST2015-08-06 02:35:08 +0800 CST 2015-08-06 02:35:08 +0800 CST

与机器同名的 Apache2 VirtualHost

  • 772

我正在使用 Debian 拥有具有规范名称的服务器(/etc/hostname在反向 DNS 中和反向 DNS 中定义)server.example.com

root@server:~# uname -a
Linux server.example.com 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1 (2015-05-24) x86_64 GNU/Linux

Apache/2.4.10 (Debian) 服务器位于 server.example.com 端口 80

现在我安装了 apache2 并做了一些基本的配置。然后我将 VirtualHosts 添加/etc/apache2/sites-available到sites-enabled. 一切正常VirtualHost,除了ServerName server.example.com. 当我尝试在资源管理器中访问该 URI 时,我得到默认虚拟主机的内容(未ServerName指定)。如果我将server.example.com.conf's ServerName 更改为不同的东西(如test.example.com)并重新加载 apache 配置,那么我可以毫无问题地访问 URI。我想知道让 VirtualHostServerName与机器的规范名称相同有什么问题。

另外,server.example.com.conf有DocumentRoot /var/www/subs/server哪些包含index.html和munin文件夹。默认 VirtualHost 中DocumentRoot /var/www/html没有munin文件夹。但是,当我尝试访问时,http://server.example.com/munin我可以进入/var/www/subs/server/munin, whilehttp://server.example.com/index.html给我带来/var/www/html/index.html.

最后,当我放入Redirect 404 /默认的 VirtualHost 时,404当我尝试同时访问http://server.example.com/和http://server.example.com/munin

添加了 VirtualHosts 的配置

/etc/apache2/sites-available/forum.example.com.conf:

# Working subdomain configuration
<VirtualHost *:80>
        ServerName forum.example.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/subs/forum
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/sites-available/server.example.com.conf:

# Not working server.example.com configuration
<VirtualHost *:80>
        ServerName server.example.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/subs/server
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/sites-available/default.conf:

# Default VirtualHost configuration 
<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /var/www/html
        #Redirect 404 /
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

root@server:~# apache2ctl -t
语法OK


添加的输出 root@server:~# apache2 -S

[Tue Aug 11 11:07:32.705684 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined
[Tue Aug 11 11:07:32.706119 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Tue Aug 11 11:07:32.706250 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Tue Aug 11 11:07:32.706406 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Tue Aug 11 11:07:32.706566 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
(... repeating few more times)
[Tue Aug 11 11:07:32.744292 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_LOG_DIR} is not defined

AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}

尽管,

/etc/apache2/apache2.conf:74:Mutex file:${APACHE_LOCK_DIR} default
/etc/apache2/envvars:21:export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX


运行后/etc/apache2/envvar我通过执行得到这个apache2 -S

VirtualHost configuration:
*:80     is a NameVirtualHost
         default server server.example.com (/etc/apache2/sites-enabled/default.conf:1)
         port 80 namevhost server.example.com (/etc/apache2/sites-enabled/default.conf:1)
         port 80 namevhost download.example.com (/etc/apache2/sites-enabled/download.example.com.conf:1)
         port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com.conf:1)
                 alias www.example.com
         port 80 namevhost forum.example.com (/etc/apache2/sites-enabled/forum.example.com.conf:1)
         port 80 namevhost forumold.example.com (/etc/apache2/sites-enabled/forumold.example.com.conf:1)
         port 80 namevhost forumtest.example.com (/etc/apache2/sites-enabled/forumtest.example.com.conf:1)
         port 80 namevhost mail.example.com (/etc/apache2/sites-enabled/mail.example.com.conf:1)
         port 80 namevhost ro.example.com (/etc/apache2/sites-enabled/ro.example.com.conf:1)
         port 80 namevhost server.example.com (/etc/apache2/sites-enabled/server.example.com.conf:1)
         port 80 namevhost anotherexample.com (/etc/apache2/sites-enabled/anotherexample.com.conf:1)
                 alias www.anotherexample.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
virtualhost
  • 2 2 个回答
  • 1947 Views

2 个回答

  • Voted
  1. Best Answer
    covener
    2015-08-10T05:57:22+08:002015-08-10T05:57:22+08:00

    在基于 debian 的发行版中,默认的虚拟主机根本没有指定 ServerName,这实际上意味着它最终以系统主机名作为其 ServerName。

    由于它首先列出,因此它将掩盖任何具有相同 ServerName 的后续虚拟主机。

    我建议禁用随附的默认虚拟主机并添加您自己的指定服务器名称但不使用您感兴趣的服务器名称。

    • 4
  2. unlo
    2015-08-08T06:59:24+08:002015-08-08T06:59:24+08:00

    来自 apache-doc:如果未指定 ServerName,则服务器尝试通过对 IP 地址执行反向查找来推断主机名。如果在 ServerName 中未指定端口,则服务器将使用传入请求中的端口。为了获得最佳可靠性和可预测性,您应该使用 ServerName 指令指定明确的主机名和端口。

    +

    本质上,主服务器被视为构建每个虚拟主机的“默认”或“基础”。但是这些主服务器定义在配置文件中的位置在很大程度上是无关紧要的——当最终合并发生时,主服务器的整个配置已经被解析。因此,即使主服务器定义出现在虚拟主机定义之后,它也可能会影响虚拟主机定义。

    • 0

相关问题

  • 阿帕奇虚拟主机

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 中的动态虚拟主机

  • VirtualHost / NameVirtualHost 背后的逻辑是什么

  • 如何设置 Jetty 6 和 Jboss 4.0.5 虚拟主机?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve