Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache Virtualhost更喜欢;“违约”;新站点的服务器_Apache_.htaccess_Ubuntu_Virtualhost - Fatal编程技术网

Apache Virtualhost更喜欢;“违约”;新站点的服务器

Apache Virtualhost更喜欢;“违约”;新站点的服务器,apache,.htaccess,ubuntu,virtualhost,Apache,.htaccess,Ubuntu,Virtualhost,我有一个运行Ubuntu的DigitalOcean droplet 在它上面,我使用Apache托管了三个站点。我正在尝试添加第四个“newsite.com”,从另一个主机交换。第四个站点位于另一个启用SSL的环境中 现有的三个站点运行良好。他们使用LetsEncrypt启用SSL,我使用虚拟主机使用相同的IP设置多个域。但是,对于第四个站点,即新站点,如果我尝试查看该站点(通过编辑Win10主机文件指向服务器IP),我会看到其他三个站点中的一个,“oldsite1.com”,它是按字母顺序排列

我有一个运行Ubuntu的DigitalOcean droplet

在它上面,我使用Apache托管了三个站点。我正在尝试添加第四个“newsite.com”,从另一个主机交换。第四个站点位于另一个启用SSL的环境中

现有的三个站点运行良好。他们使用LetsEncrypt启用SSL,我使用虚拟主机使用相同的IP设置多个域。但是,对于第四个站点,即新站点,如果我尝试查看该站点(通过编辑Win10主机文件指向服务器IP),我会看到其他三个站点中的一个,“oldsite1.com”,它是按字母顺序排列的列表中最高的。据我所知,Apache在启用的站点列表中不断向下选择一个站点。新站点未启用SSL,因为在更改DNS之前,我无法运行LetsEncrypt

新站点的.conf文件如下所示:

<VirtualHost *:80>
        ServerAdmin webmaster@newsite.com
        ServerName newsite.com
        ServerAlias www.newsite.com
        DocumentRoot /var/www/newsite.com/public_html

        <Directory /var/www/newsite.com/public_html>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

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

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

RewriteEngine on
RewriteCond %{SERVER_NAME} =newsite.com [OR]
RewriteCond %{SERVER_NAME} =www.newsite.com
RewriteRule ^ http://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
我曾多次尝试清空newsite.htaccess并重新启动apache,但当我尝试查看newsite.com时,总是显示oldsite1.com


假设my.conf或.htaccess没有问题,为什么Apache更喜欢列表中第一个站点的vhost?

您正在强制使用ssl。加载<代码>http://newsite.com您将被重定向到
https://newsite.com

您在端口80上只有newsite.com的vhost,而在端口443上没有

由于端口443上没有请求域的vhost,因此将为您提供默认站点

如果您对以下部分进行注释,您将获得预期的站点:

#Force SSL
RewriteEngine On
#RewriteCond %{SERVER_PORT} 80 
#RewriteRule ^(.*)$ https://newsite.com/$1 [R=301,L]

回答得好@Thakkie!
VirtualHost configuration:

*:443                  is a NameVirtualHost
         default server oldsite1.com (/etc/apache2/sites-enabled/oldsite1.com-le-ssl.conf:2)
         port 443 namevhost oldsite1.com (/etc/apache2/sites-enabled/oldsite1.com-le-ssl.conf:2)
                 alias www.oldsite1.com
         port 443 namevhost oldsite2.com (/etc/apache2/sites-enabled/oldsite2.com-le-ssl.conf:2)
                 alias www.oldsite2.com
         port 443 namevhost oldsite3.com (/etc/apache2/sites-enabled/oldsite3.com-le-ssl.conf:2)
                 alias www.oldsite3.com
*:80                   is a NameVirtualHost
         default server 127.0.0.1 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost 127.0.0.1 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost oldsite1.com (/etc/apache2/sites-enabled/oldsite1.com.conf:1)
                 alias www.oldsite1.com
         port 80 namevhost oldsite2.com (/etc/apache2/sites-enabled/oldsite2.com.conf:1)
                 alias www.oldsite2.com
         port 80 namevhost oldsite3.com (/etc/apache2/sites-enabled/oldsite3.com.conf:1)
                 alias www.oldsite3.com
         port 80 namevhost newsite.com (/etc/apache2/sites-enabled/newsite.com.conf:1)
                 alias www.newsite.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: 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
#Force SSL
RewriteEngine On
#RewriteCond %{SERVER_PORT} 80 
#RewriteRule ^(.*)$ https://newsite.com/$1 [R=301,L]