Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Общий по Linux (http://forum.oszone.net/forumdisplay.php?f=9)
-   -   Несколько сайтов на одном IP (http://forum.oszone.net/showthread.php?t=304786)

Rubichek 01-09-2015 15:29 2548295

Несколько сайтов на одном IP
 
Здравствуйте, подскажите что не так делаю нужно сделать на 1ip несколько сайтов (ip/site1, ip/site2 )

1. Debian 7
2. Apache 2.4

Создал директорию под сайт

/var/www/test1/public_html

и

/var/www/test2/public_html

конфиг первого (второй делал по аналогии)

Скрытый текст

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port t$
# 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@test1
ServerName test1
ServerAlias www.test1
DocumentRoot /var/www/test1/public_html

<Directory /var/www/test1/>
Require all granted
</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>

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


Включаем сайт:
$ sudo a2ensite test1

Перезагружаем apache:
$ sudo service apache2 restart

если зайти по локальному ip все ок

если зайти по test1/ тоже работает

если зайти по 192.168.0.112/test1/ - Not Found

Rubichek 02-09-2015 17:28 2548736

никто не сталкивался?

SpectreKr 03-09-2015 09:50 2548945

Все правильно работает, если хотите чтоб было IP\test1, то надо делать DocumentRoot /var/www. И заходить IP/test1, и IP/test2 соответственно. Но правильней как сейчас настроено, и ходить test1, и test2 соответственно.

El Scorpio 04-09-2015 01:34 2549357

Цитата:

Цитата Rubichek
если зайти по 192.168.0.112/test1/ - Not Found »

Всё правильно.

Потому что при
Цитата:

Цитата Rubichek
<Directory /var/www/test1/> »

получается, что апач пытается открыть /var/www/test1/test1

Если хотите, чтобы работал адрес 192.168.0.112/test1/ и прочие, значит нужно указать для "сайта по умолчанию" каталог /var/www/

Код:

<VirtualHost *:80>
        <Directory /var/www/>

<VirtualHost site1:80>
        <Directory "/var/www/site1">
и т.д.


Rubichek 04-09-2015 18:06 2549631

Спасибо большое за ответы!

Цитата:

Цитата SpectreKr
Но правильней как сейчас настроено, и ходить test1, и test2 соответственно. »

а как тогда настроить правильно что бы можно было из вне попасть статика есть.

Rubichek 04-09-2015 18:23 2549636

пробовал изменить путь DocumentRoot не пускает по ip

как то так?

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port t$
# 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@test1
ServerName test1
ServerAlias www.test1
DocumentRoot /var/www/ // правим путь

<VirtualHost site1:80> //добавляем еще один VirtualHost
<Directory "/var/www/site1"> //правим путь к сайту
</Directory>

</VirtualHost> // закрываем VirtualHost

# 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

Rubichek 05-09-2015 18:43 2549950

если зайти по внешнему ip то отображается страница apache

SpectreKr 07-09-2015 12:58 2550492

А если указать:
ServerName test1
ServerAlias www.test1
ServerAlias test1/test1 или 192.168.0.112/test1
DocumentRoot /var/www/test1

Rubichek 07-09-2015 16:02 2550549

не работает! Может что то не так изначально сделал! Может есть рабочая инструкция перезалью ос и по пробую с нуля настроить?

SpectreKr 08-09-2015 10:36 2550815

Так, смотрите, сейчас у вас в внутренней сети ходит правильно при настройках:
ServerName test1
ServerAlias www.test1
DocumentRoot /var/www/test1
Теперь чтоб можно было заходить с внешней, вы должны, сделать доменные имена, например test1.ru и test2.org, на любом свободном ДНС или у регистратора имени, например яндекс ДНС или любом другом, зарегистрировать А запись с именем сайта и белым IP. В настройках добавить алиас:
ServerAlias www.test1.ru и соответственно
ServerAlias www.test2.org
После 4 часов, в среднем, можно будет заходить по этим именам. Если же без регистрации и белый IP/test1 заходить надо, тогда настраиваем и внутреннюю сетку, так чтоб ходило серый IP/test1 указав
ServerName test1
DocumentRoot /var/www
Если я правильно все понял. Просто систему IP, имя, IP\каталог в полной связке ни где не встречал. Когда настраивал свой сервер перечитал куча, в основном советуют связку IP, имя.

Rubichek 08-09-2015 11:44 2550840

так это и есть имя просто без test1.com я дал имя test1 по ходу так нельзя

SpectreKr 08-09-2015 11:57 2550848

можно, если есть локальный днс который обработает это имя. Тогда настройте так:
ServerName test1
ServerAlias test1.com
ServerAlias www.test1.com
DocumentRoot /var/www/test1/
Должно работать со всех сетей.

Nigelist 07-11-2015 07:59 2572367

Привет всем!

Имеется несколько сайтов на одном сервере (Debian 8). Конфиг следующий:
Скрытый текст
Код:

NameVirtualHost *:80
 
<VirtualHost *:80>
        ServerName site1.example.org
 
        ServerAdmin root@example.org
        DocumentRoot /var/www/site1
 
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
 
<VirtualHost *:80>
        ServerName site2.example.org
 
        ServerAdmin root@example.org
        DocumentRoot /var/www/site2
 
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
 
<VirtualHost *:80>
        ServerName site3.example.org
 
        ServerAdmin root@example.org
        DocumentRoot /var/www/site3
 
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>



Буквально несколько дней назад, вышеуказанный конфиг работал просто отлично. Но сейчас не работает, при попытке перезапуска apache2, выдает следующее:
Код:

Job for apache2.service failed. See 'systemctl status apache2.service' and 'journalctl -xn' for details.
А при запросе статуса:
Скрытый текст
Код:

ноя 05 10:41:56 forum systemd[1]: Reload failed for LSB: Apache2 web server.
ноя 05 10:51:46 forum systemd[1]: Reloading LSB: Apache2 web server.
ноя 05 10:51:46 forum apache2[9775]: Reloading web server: apache2 failed!
ноя 05 10:51:46 forum apache2[9775]: The apache2 configtest failed. Not doing anything. ... (warning).
ноя 05 10:51:46 forum apache2[9775]: Output of config test was:
ноя 05 10:51:46 forum apache2[9775]: apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of ...n system
ноя 05 10:51:46 forum apache2[9775]: Action 'configtest' failed.
ноя 05 10:51:46 forum apache2[9775]: The Apache error log may have more information.
ноя 05 10:51:46 forum systemd[1]: apache2.service: control process exited, code=exited status=1
ноя 05 10:51:46 forum systemd[1]: Reload failed for LSB: Apache2 web server.
Hint: Some lines were ellipsized, use -l to show in full.



В общем Apache ругается на 140 строку. Но там ошибок нет, только подключение модов:
Код:

IncludeOptional mods-enabled/*.load
Мне непонятно, почему, конфиг, который работал вчера отказывается работать сегодня. Изменений в apache.conf не делал. Единственные изменения:
  • Установил sendmail
  • Раскомментировал и настроил в php.ini строку:
    Код:

    sendmail_path = /usr/sbin/sendmail -t -i -f root@example.org


Время: 08:03.

Время: 08:03.
© OSzone.net 2001-