Apache配置和会话变量SERVER_NAME

作为日常工作的一部分,我维护一个网站(不是由我开发,我不是网络开发人员),该网站具有许多基于传入URL的外观。 最近,一位客户为新的L&F注册了一个新域,我像往常一样在服务器上进行了所有配置(我有使用手册,该怎么做),但是这次不起作用。

我在/etc/httpd/conf.d中有服务器虚拟主机,它们都是相同的

    # The virtual host configuration for my.website.com
    #<Directory "/var/www/my.website.com/html">

    <Directory "/var/www/my.website.com/html">
            Order allow,deny
            Allow from all
            AllowOverride Limit FileInfo Indexes
    </Directory>

    <Files ~ ".passwd">
            Order allow,deny
            Deny from all
    </Files>

    <Virtualhost *:80>
            ServerName newlookandfell.mycustomer.com
            ServerAlias newlookandfell.mycustomer.com
            DocumentRoot /var/www/my.website.com/html
            ErrorLog logs/mycustomer-error_log
            CustomLog logs/mycustomer-access_log common

            RewriteEngine On
            RewriteLog "/var/log/httpd/rewrite.log"
            RewriteLogLevel 1
            ProxyPreserveHost On

    </VirtualHost>

然后我有一个php文件,它根据会话变量SERVER_NAME选择要包含的L&F

    class ConfigLoader
    {
        /**
         * Determine URL used for accessing the page and load proper config file
         * @return
         */
        public static function loadConfiguration()
        {

            $server = $_SERVER['SERVER_NAME'];

            switch($server)
            {
                case 'newlookandfell.mycustomer.com':
                    require_once 'lookandfeel/mycustomer.php';
                    break;
                case 'lookandfell.anothercustomer.com':
                    require_once 'lookandfeel/anothercustomer.php';
                    break;
    ...... and so on
                default:
                    require_once 'lookandfeel/default.php';
                    break;

我注意到对newlookandfell.mycustomer.com的所有请求都解析为默认外观,因此我检查了Apache access_log(/ etc / httpd / logs / access_log),该请求看起来正确。

XX.XX.XX.XX - - [25/Nov/2019:07:42:40 +0000] "GET / HTTP/1.1" 200 3379
"http://newlookandfell.mycustomer.com/" "Mozilla/5.0 (Windows NT 10.0;
WOW64; Trident/7.0; rv:11.0) like Gecko"

但是,如果我打印变量$ server,则会得到公共IP地址。 作为“补丁”,我修改了案例以包括IP地址,但这不是我喜欢的解决方案,如果下一个L&F遇到相同的问题,我该怎么办?

您是否知道为什么以及如何解决此问题? 预先感谢

编辑:对虚拟主机的每次更改后,Apache都会重新启动

wt814 回答:Apache配置和会话变量SERVER_NAME

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3037823.html

大家都在问