【问题标题】:Where does Apache read $domain variable from?Apache 从哪里读取 $domain 变量?
【发布时间】:2021-07-24 23:52:31
【问题描述】:

在我启用了 Wordpress 的 Ubuntu 实例中,我有一个 000-default.conf 文件,其中包含以下设置:

./apache2/sites-available/000-default.conf:        ServerName $domain
./apache2/sites-available/000-default.conf:        ServerAlias www.$domain

grepping for \$domain inside etc 基本上只给了我这个文件。

Apache 在运行我的网站时从哪里获得这个值?


完整的 000-default.conf:

UseCanonicalName On

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        ServerName $domain
        ServerAlias www.$domain

        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    <FilesMatch \.php$>
        # 2.4.10+ can proxy to unix socket
        SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>

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

【问题讨论】:

  • 显示完整的 000-default.conf
  • @Exampleperson 添加。你看到什么相关的了吗?
  • @Adeerlike 请同时显示 000-default 包含在主配置中的部分。
  • @JohannesH。只是# Include the virtual host configurations: IncludeOptional sites-enabled/*.conf
  • 包括sites-enabled/000-default.conf - 您在上面发布了sites-available/000-default.conf。你确定它们是相同的/符号链接的吗?

标签: apache ubuntu server


【解决方案1】:

$domain 不是 Apache HTTPD 中的预定义变量。 list of variables in the documentation 没有。

由于在 Apache 中使用 %{VAR}-notation 访问环境变量,因此也不会从环境中读取它。

它也不在我的 000-default.conf 中 - 这意味着它必须是特定于您的设置的东西。

确实如此! Wordpress 将该文件包含在 sites-available 中,并以 $domain 作为占位符。在安装过程中,文件被复制到sites-enabled 并替换占位符。查看sites-enabled/000-default.conf,而不是$domain,应该是您的域。

【讨论】:

  • Apache 从 Wordpress PHP 脚本中包含它是否有意义[以及如何]?
  • 您到底想在哪里包含什么?但一般来说,PHP 不能与 apache 配置交互。 Apache 在启动期间读取该配置(除非您发出重新加载),并在调用任何 PHP 解释器之前对其进行解析。
  • 这就是为什么我想知道它从哪里获得 $domain 的价值。我的系统唯一有这个变量的地方是这个网站的 PHP 文件......
  • 正如我所说 - 在 wordpress 安装期间,它应该将实际域复制到该 apache 配置文件中。如果您安装了 wordpress,但它仍然在 apache 中显示 $domain,则说明有问题 - 这应该不起作用。您确定您正在查看实际的 Apache 配置而不是 wordpress 模板吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-04
  • 2014-12-19
  • 2015-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-30
相关资源
最近更新 更多