虚拟主机域名无法让我进入正确的文件夹

虚拟主机域名无法让我进入正确的文件夹

我正在尝试在单个 Ubuntu 16.04 安装上设置多个网站,到目前为止已经安装了带有 LAMP 和 SSL(Letsencrypt)的 Ubuntu。

  • Ubuntu 16.04
  • PHP 7.0
  • Apache2
  • 玛拉雅数据库

问题:第一个域名(website1.com)指向正确的文件夹(var/www/html/website1),但我的第二个域名(website2.com)指向第一个(var/www/html/website1)。

我已经创建了 /etc/apache2/sites-available/website1.conf 和 /etc/apache2/sites-available/website2.conf 文件并进行如下配置:

网站1.conf

<IfModule mod_ssl.c><VirtualHost *:443>
ServerAdmin [email protected]
ServerName website1.com
ServerAlias www.website1.com
DocumentRoot /var/www/html/website1 
<Directory /> 
    Options FollowSymLinks 
    AllowOverride None 
</Directory>
<Directory /var/www/html/website1> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all
</Directory> 
    SSLCertificateFile /etc/letsencrypt/live/website2.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/website2.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

网站2.conf

<IfModule mod_ssl.c><VirtualHost *:443>
ServerAdmin [email protected]
ServerName website2.com
ServerAlias www.website2.com
DocumentRoot /var/www/html/website2
<Directory /> 
    Options FollowSymLinks 
    AllowOverride None 
</Directory>
<Directory /var/www/html/website2> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all
</Directory> 
    SSLCertificateFile /etc/letsencrypt/live/website2.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/website2.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

apachectl -S 输出

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:443                  is a NameVirtualHost
         default server website1.com (/etc/apache2/sites-enabled/website1-le-ssl.conf:2)
         port 443 namevhost website1.com (/etc/apache2/sites-enabled/website1-le-ssl.conf:2)
             alias www.website1.com
     port 443 namevhost website2.com (/etc/apache2/sites-enabled/website2-le-ssl.conf:2)
             alias www.website2.com
*:80                   website2.com (/etc/apache2/sites-enabled/website2.conf:1)
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/lock/apache2" mechanism=fcntl
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
  • 我已经启用(a2ensite)website1.conf 和 a2ensite website2.conf;
  • 我已经禁用(a2dissite)000-default.conf 和 default-ssl.conf;
  • 我也尝试过 a2ensite default-ssl.conf;
    每次更改后我都重新启动(sudo systemctl restart apache2)。

每次我尝试访问 website2.com 时,它都会直接转到 website1.com

请提供帮助,并提前感谢您的想法!

相关内容