Виртуальные хосты Ubuntu 19.04

Я прочитал несколько статей и прочесал stackExchange, но не смог решить проблему. У меня есть два доменных имени, и я хочу создать виртуальные хосты для каждого из них. Я создал отдельные папки, где я размещаю index.html для каждого домена. Я также создал файл conf, в / etc / apache2 / sites-available файлы выглядят следующим образом:

NameVirtualHost x.x.x.x:80

<VirtualHost x.x.x.x: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 example1.org
        ServerAlias www.example1.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/org/public_html
        #Options +FollowSymlinks
        # 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
        #<Directory /var/www/html/org/public_html>
        # Options -Indexes +FollowSymLinks +MultiViews
        # AllowOverride All
        # Require all granted
        #</Directory>

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example1aorg-error.log
        CustomLog ${APACHE_LOG_DIR}/example1org-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>



<VirtualHost x.x.x.x: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 example2.com
        ServerAlias www.example2.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/com/public_html
        #Options +FollowSymlinks
        # 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
        #<Directory /var/www/html/com/public_html>
        # Options -Indexes +FollowSymLinks +MultiViews
        # AllowOverride All
        #</Directory>

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example2com-error.log
        CustomLog ${APACHE_LOG_DIR}/example2com-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>

xxxx - публичный IP
example1 и example2 - это не домены, с которыми я работаю, а просто фиктивные домены.

Когда я пытаюсь загрузить домен на моем сервере, сервер всегда показывает мне индексный файл для example1 .

Я не уверен, что делать, похоже, виртуальный хост не будет работать с двумя доменами.

1
задан 24 August 2019 в 12:22

2 ответа

Хорошо, после поиска и восстановления моего сервера, я наконец нашел решение своей проблемы. Я на самом деле передавал моему серверу I.P. своему домену, вместо того, чтобы настроить DNS. Я купил свой домен у GoDaddy, и мой сервер с Linode. Я следовал за следующими направлениями для конфигурирования моего DNS.

https://www.linode.com/docs/platform/manager/dns-manager/

Затем вошел в Godaddy.com и добавил Серверы имен к моему домену, с помощью следующего руководства:

https://www.godaddy.com/help/set-nameservers-for-domains-hosted-and-registered-with-godaddy-12316

После того как я обновил Серверы имен, потребовалось приблизительно 48 часов для URL для указания на корректный webroot через браузер.

0
ответ дан 7 December 2019 в 19:02

Если Вы устанавливаете через Кв., Вы, возможно, должны проверить, чтобы видеть, существует ли конфигурация по умолчанию. Если существует, необходимо отключить его путем удаления его из sites-enabled список.

Не видя, как example1.com настроен, трудно сказать, где проблема. Но если это настраивается точно так же, как example2.com, гарантируйте это DocumentRoot указывает на другой каталог. Легко пропустить.

Быстрое редактирование: VirtualHosts будет определенно работать больше чем на один домен. Я в настоящее время выполняю его с тремя доменами и несколькими субдоменами, всеми с VirtualHost. SSL хитер, хотя..., но это вне темы.

+++

Дополнительное редактирование после обеспечения example1.com конфигурация.

Без комментариев похоже, что Вы - конфигурация, похож на это:

NameVirtualHost x.x.x.x:80

<VirtualHost x.x.x.x:80>
        ServerName example1.org
        ServerAlias www.example1.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/org/public_html

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example1aorg-error.log
        CustomLog ${APACHE_LOG_DIR}/example1org-access.log combined
</VirtualHost>



<VirtualHost x.x.x.x:80>
        ServerName example2.com
        ServerAlias www.example2.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/com/public_html

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example2com-error.log
        CustomLog ${APACHE_LOG_DIR}/example2com-access.log combined
</VirtualHost>

Разность между ними, помимо доменов, org для example1 и com для example2. example2 имеет журналы при посещении его из браузера? Можно ли предоставить им также?

0
ответ дан 7 December 2019 в 19:02

Другие вопросы по тегам:

Похожие вопросы: