第一次使用Apache,似乎无法设置两个站点

时间:2017-06-19 09:59:54

标签: php apache ubuntu ubuntu-16.04

首次使用Ubuntu 16.04 LTS Server设置Apache2服务器。我有一个网站工作,我很满意。 现在我想在同一台服务器上创建第二个站点,并通过internalIP / site1和internalIP / site2

访问它们

我为第二个站点创建了目录:/var/www/html/site2并在001-default.conf中创建了一个名为/etc/apache2/sites-available/的.conf文件,然后输入:

<VirtualHost *:80>
    DocumentRoot "/var/www/html/site2/"
    ServerName site2
</VirtualHost>

然后使用sudo a2ensite site2启用它。

我的site1的sites / available中的.conf文件是/etc/apache2/sites-available/000-default.conf,如下所示:

<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

        ServerAdmin webmaster@localhost
        ServerName support
        ServerAlias support
        DocumentRoot /var/www/html/osticket/

        # 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>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

现在奇怪的(对我而言)是每当我进入服务器的内部IP时,我立即登陆Site1。也许我改变了一些与此相关的配置,但我不记得了......我知道我必须先去InternalIP / osticket(site1的名称)来访问它。我无法通过internalIP / site2或类似的东西访问site2。我收到404错误。

请记住,这是我第一次尝试学习并提供足够的信息,非常感谢。

1 个答案:

答案 0 :(得分:1)

  

现在奇怪(对我而言)是每当我进入服务器的内部IP时,我立即登陆Site1。

这很正常。默认站点是首先定义的站点。如果您不通过服务器知道的主机名访问该站点,则会获得第一个。

  

我无法通过internalIP / site2

访问site2

那是因为/var/www/html/osticket/site2不存在。

您需要访问http://site2/而不是http://192.168.1.123/site2/

您正在使用虚拟名称托管。您需要使用名称。

(为了举例,我编写了一个IP地址)。