Apache 虚拟主机问题

Apache 虚拟主机问题

我尝试从同一个 ubuntu 服务器加载 2 个网站 - 一个通过域名,另一个通过 IP 地址,但没有任何进展。

我在 EC2 实例上运行一个网站。我将默认虚拟主机指向网站文件夹。该网站有自己的域名。

但随后我需要安装 phpmyadmin 并创建了第二个虚拟主机,因此现在我有以下内容/etc/apache2/sites-available/

-rw-r--r-- 1 root root 1492 Oct 29 23:11 000-default.conf
-rw-r--r-- 1 root root 6437 Jan  7  2014 default-ssl.conf
-rw-r--r-- 1 root root 1500 Oct 29 22:34 phpmyadmin.conf

000-default.con 包含以下内容:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com
    ServerName http://www.example.com
    ServerAlias http://example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/example

    <Directory "/var/www/example">
            AllowOverride All
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

phpmyadmin.conf 包含以下内容:

<VirtualHost phpmyadmin:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/phpmyadmin/index.php

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

我的问题是,每当我访问时example.com,我都能按预期获得我的网站。

但是,我尝试通过以下 IP 地址加载 phpmyadmin:,x.x.x.x/phpmyadmin但在 mysite.com 上出现页面未找到错误。

如果我尝试,也会发生同样的事情example.com/phpmyadmin。我不确定如何解决这个问题。

更新:

ubuntu@ip-10-0-0-106 /etc/apache2/sites-available $ apachectl -S
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server ip-10-0-0-106.eu-west-1.compute.internal (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost ip-10-0-0-106.eu-west-1.compute.internal (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost www.example.com (/etc/apache2/sites-enabled/example.conf:1)
                 alias http://example.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

答案1

您只有一个有效且处于活动状态的虚拟主机。另一个虚拟主机无效,因为名称phpmyadmin无法解析为您的任一 IP 地址。

相反,您应该<VirtualHost *>在两个主机上都使用,并将您想要通过 IP 地址处理请求的主机放入 httpd.conf 中,这样它就会成为默认主机。

相关内容