Страница 1 из 1

Несколько сайтов (VirtualHost) на Apache

Добавлено: Чт июл 02, 2009 3:26 pm
Dmitiry_Silverston
Уважаемые гуру, подскажите пожалуста как можно организовать сайт + веб интерфейс биллинга. А именно интересует вход на сайт типа: stranichka.net, вход на биллинг billing.stranichka.net (или если в локалке то, к примеру, http://192.168.0.1 - сайт и http://192.168.0.1/billing/ - биллинг соответсенно.)

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Чт июл 02, 2009 6:28 pm
lasik
1 настройки аппачи
2 файл .хтдокс

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Чт июл 02, 2009 8:03 pm
Dmitiry_Silverston
httpd.conf - вернее важная оконцовка:

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at <URL:http://www.apache.org/docs/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#ServerAlias silver.priv stats.silver.priv

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#Alias /silver/ "/usr/local/www/joomla/"
DocumentRoot /usr/local/www/joomla/
# ServerAdmin silver@blabla.net
# ServerName silver.priv
# ServerAlias silver.priv
DocumentRoot /usr/local/www/joomla/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
# ErrorLog /var/logs/com-error_log
# CustomLog /var/logs/com-access_log common
<Directory /usr/local/www/joomla/>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
options +Includes
options +Indexes
</Directory>
#</VirtualHost>

#Abills version 0.4. Default ABillS port is 9443
Listen 9443
#Alias for web report
Alias /reports/ "/usr/local/abills/webreports"
<Directory "/usr/local/abills/webreports">
AllowOverride All
Order allow,deny
Allow from all
</Directory>

# Main server config
<VirtualHost _default_:9443>
ServerName abills
ServerAlias /abills "/usr/local/abills/cgi-bin/"
DocumentRoot /usr/local/abills/cgi-bin/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
#ServerName http://www.example.com:9443
#ServerAdmin admin@example.com
ErrorLog /var/log/abills-error.log
#TransferLog /var/log/abills-access.log
CustomLog /var/log/abills-access_log common

<IfModule ssl_module>
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/abills/Certs/server.crt
SSLCertificateKeyFile /usr/local/abills/Certs/server.key
<FilesMatch "\.(cgi)$">
SSLOptions +StdEnvVars
</FilesMatch>
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0

CustomLog /var/log/abills-ssl_request.log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</IfModule>


# User interface
<Directory '/usr/local/abills/cgi-bin/'>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
<IfModule ssl_module>
SSLOptions +StdEnvVars
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_CGI_AUTHORIZATION:%1]

#Anti TRACE
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

Options Indexes ExecCGI SymLinksIfOwnerMatch
</IfModule>

AddHandler cgi-script .cgi
Options Indexes ExecCGI FollowSymLinks
AllowOverride none
DirectoryIndex index.cgi
Order allow,deny
Allow from all

<Files ~ "\.(db|log)$">
Order allow,deny
Deny from all
</Files>

#For hotspot solution
ErrorDocument 404 "/abills/"
directoryIndex "/abills" index.cgi

</Directory>

#Admin interface
<Directory '/usr/local/abills/cgi-bin/admin/'>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
<IfModule ssl_module>
SSLOptions +StdEnvVars
</IfModule>

AddHandler cgi-script .cgi
Options Indexes ExecCGI FollowSymLinks
AllowOverride none
DirectoryIndex index.cgi
order deny,allow
allow from all
</Directory>

</VirtualHost>

файл .хтдокс -? нету...

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Пт июл 03, 2009 11:02 am
ran
Dmitiry_Silverston писал(а):Уважаемые гуру, подскажите пожалуста как можно организовать сайт + веб интерфейс биллинга. А именно интересует вход на сайт типа: stranichka.net, вход на биллинг billing.stranichka.net (или если в локалке то, к примеру, http://192.168.0.1 - сайт и http://192.168.0.1/billing/ - биллинг соответсенно.)
дык через виртуал хостс и разруливается... хошь по ип, хошь - по имени...

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Вс июл 05, 2009 8:50 am
sopov
А если нехотите чтобы пароли выших юзеров потырили нужно https заюзать.

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Вс июл 05, 2009 2:23 pm
Dmitiry_Silverston
Зделал так:
### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at <URL:http://www.apache.org/docs/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost silver.priv
#ServerAlias silver.priv stats.silver.priv

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost silver.priv:80>
Alias /silver.priv/ "/usr/local/www/joomla/"
DocumentRoot /usr/local/www/joomla/
ServerAdmin silver@blabla.net
ServerName silver.priv
ServerAlias silver.priv
DocumentRoot /usr/local/www/joomla/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
# ErrorLog /var/logs/com-error_log
# CustomLog /var/logs/com-access_log common
<Directory /usr/local/www/joomla/>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
options +Includes
options +Indexes
</Directory>
</VirtualHost>

#Abills version 0.4. Default ABillS port is 9443
Listen 9443
#Alias for web report
Alias /reports/ "/usr/local/abills/webreports"
<Directory "/usr/local/abills/webreports">
AllowOverride All
Order allow,deny
Allow from all
</Directory>

# Main server config
<VirtualHost stats.silver.priv:9443>
ServerName silver.abills.priv
ServerAlias /abills "/usr/local/abills/cgi-bin/"
DocumentRoot /usr/local/abills/cgi-bin/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
#ServerName http://www.example.com:9443
#ServerAdmin admin@example.com
ErrorLog /var/log/abills-error.log
#TransferLog /var/log/abills-access.log
CustomLog /var/log/abills-access_log common

<IfModule ssl_module>
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/abills/Certs/server.crt
SSLCertificateKeyFile /usr/local/abills/Certs/server.key
<FilesMatch "\.(cgi)$">
SSLOptions +StdEnvVars
</FilesMatch>
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0

CustomLog /var/log/abills-ssl_request.log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</IfModule>


# User interface
<Directory '/usr/local/abills/cgi-bin/'>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
<IfModule ssl_module>
SSLOptions +StdEnvVars
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_CGI_AUTHORIZATION:%1]

#Anti TRACE
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

Options Indexes ExecCGI SymLinksIfOwnerMatch
</IfModule>

AddHandler cgi-script .cgi
Options Indexes ExecCGI FollowSymLinks
AllowOverride none
DirectoryIndex index.cgi
Order allow,deny
Allow from all

<Files ~ "\.(db|log)$">
Order allow,deny
Deny from all
</Files>

#For hotspot solution
ErrorDocument 404 "/abills/"
directoryIndex "/abills" index.cgi

</Directory>

#Admin interface
<Directory '/usr/local/abills/cgi-bin/admin/'>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
<IfModule ssl_module>
SSLOptions +StdEnvVars
</IfModule>

AddHandler cgi-script .cgi
Options Indexes ExecCGI FollowSymLinks
AllowOverride none
DirectoryIndex index.cgi
order deny,allow
allow from all
</Directory>

</VirtualHost>

Потом начал получать сообщения об ошибке после перезапуска апача: Cannot resolve host name....
Прикрутил hosts:

127.0.0.1 localhost silver.priv
127.0.0.1 localhost stats.silver.priv

Теперь вроде всё резолвится, но кажется проблемы с DNS:

# nslookup
> silver.priv
Server: 127.0.0.1
Address: 127.0.0.1#53

** server can't find silver.priv: NXDOMAIN
> stats.silver.priv
Server: 127.0.0.1
Address: 127.0.0.1#53

** server can't find stats.silver.priv: NXDOMAIN
>

По ссылкам silver.priv и stats.silver.priv никуда не заходит, по айпишникам так же.

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Пн июл 06, 2009 4:29 am
sopov
в httpd.conf добавте следующее:

Код: Выделить всё

Listen *:80
<IfModule mod_ssl.c>
Include conf/ssl.conf
</IfModule>
ServerName local.lan.ua
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

# Virtual hosts
NameVirtualHost *
<VirtualHost *>
    ServerName local.lan.ua
</VirtualHost>


<VirtualHost *>
    ServerName stat.local.lan.ua
    ServerAlias www.stat.local.lan.ua
    DocumentRoot /usr/local/apache2/htdocs/stat
    ServerAdmin admin@local.lan.ua
    ErrorLog /usr/local/apache2/logs/error_log
    CustomLog /usr/local/apache2/logs/access_log common
</VirtualHost>
Далее в /usr/local/apache2/htdocs/stat положите index.html следующего содержания:

Код: Выделить всё

<html>
<head><meta http-equiv="Refresh" content="0;URL=https://stat.local.lan.ua/">
</head>
<body onload="window.open('https://stat.local.lan.ua/','_top')">
</body>
</html>
Это нужно для того, чтобы если юзер зайдет на stat.local.lan по http, то его переадресует на https. Это можно сделать и с помощью модуля rewrite, но я сделал так.

Далее создаем или правим файл ssl.conf

Код: Выделить всё

Listen *:443

<VirtualHost stat.local.lan.ua:443>
DocumentRoot "/usr/abills/cgi-bin"
ServerName stat.local.lan.ua
ServerAdmin admin@local.lan.ua
ErrorLog /usr/local/apache2/logs/secure_ssl_error_log
TransferLog /usr/local/apache2/logs/secure_ssl_access_log

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/apache2/ssl.crt/server.crt
SSLCertificateKeyFile /usr/local/apache2/ssl.key/server.key

<Directory "/usr/abills/cgi-bin/">
           SSLOptions +StdEnvVars
        <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP:Authorization} ^(.*)
        RewriteRule ^(.*) - [E=HTTP_CGI_AUTHORIZATION:%1]
        Options Indexes ExecCGI SymLinksIfOwnerMatch
        </IfModule>
  AddHandler cgi-script .cgi
  Options Indexes ExecCGI FollowSymLinks
  AllowOverride none
  DirectoryIndex index.cgi
  Order allow,deny
  Allow from all
</Directory>

#Admin interface
<Directory "/usr/abills/cgi-bin/admin">
  AddHandler cgi-script .cgi
  Options Indexes ExecCGI FollowSymLinks
  AllowOverride none
  DirectoryIndex index.cgi
  order deny,allow
  allow from all

</Directory>
</VirtualHost>

Вот собственно и все. При условии, что установлен openssl. Ну и естественно stat.local.lan.ua должно резольвится на ip вашего сервера биллинга.

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Пн июл 06, 2009 3:57 pm
Dmitiry_Silverston
sopov писал(а):в /usr/local/apache2/htdocs/stat положите index.html
Ну например htdocs/stat нету, вместо него стандартно: DocumentRoot "/usr/local/www/apache22/data"
А сам сайт куда ложить?

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Пн июл 06, 2009 4:48 pm
sopov
Ничего страшного что нету, просто исправте пути под себя. У вас сайт будет крутится на одной машине с биллингом? Если да, то не очень хорошая затея, но всеже примерно вот так должны выглядеть виртуальные хосты:

Код: Выделить всё

# Virtual hosts
NameVirtualHost *
<VirtualHost *>
    ServerName localhost.lan.ua
</VirtualHost>

<VirtualHost *>
    ServerName local.lan.ua
    ServerAlias www.local.lan.ua
    DocumentRoot /usr/local/www   ###Сюда кладете сайт или исправте путь под себя
    ServerAdmin admin@local.lan.ua
    ErrorLog /var/log/www/error.log
    CustomLog /var/log/www/access.log common
</VirtualHost>

####Дальше идут примеры как создать еще имена
<VirtualHost *>
    ServerName ftp.local.lan.ua
    ServerAlias www.ftp.local.lan.ua
    DocumentRoot /usr/local/www/deny
    ServerAdmin admin@local.lan.ua
    ErrorLog /var/log/www/other/error.log
    CustomLog /var/log/www/other/access.log common
</VirtualHost>

<VirtualHost *>
    ServerName stat.local.lan.ua
    ServerAlias www.stat.local.lan.ua
    DocumentRoot /usr/local/apache2/htdocs/stat
    ServerAdmin admin@local.lan.ua
    ErrorLog /usr/local/apache2/logs/error_log
    CustomLog /usr/local/apache2/logs/access_log common
</VirtualHost>
Но еще раз обращу ваше внимание на то, что эти имена должны резольвиться вашим dns.
Собственно здесь виртуальный хост stat.local.lan.ua только для редиректа на https. А вот за непосредственно вход в биллинг отвечает конфиг ssl.conf листинг которого приведен мною выше. Внем собственно и описывается виртуальный хост для абиллс. Также у вас должны быть созданы сертификаты. Вобщем как запустить эту связку смотрите тут http://abills.net.ua/wiki/doku.php/abil ... che_ssl:ru

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Пн июл 06, 2009 5:49 pm
Dmitiry_Silverston
Да, именно сервер один. На нём хотелось бы совместить биллнг и небольшой сайтик (порталку), т.к. сеть небольшая и кол-во пользователей интернета не будет больше 100. С SSL пока не разобрался, да и apach22 стал выделыватся, откатил до версии 1.3.
Делая по принципу:

Код: Выделить всё

# Virtual hosts
NameVirtualHost *
<VirtualHost *>
    ServerName localhost.lan.ua
</VirtualHost>

<VirtualHost *>
    ServerName local.lan.ua
    ServerAlias www.local.lan.ua
    DocumentRoot /usr/local/www   ###Сюда кладете сайт или исправте путь под себя
    ServerAdmin admin@local.lan.ua
    ErrorLog /var/log/www/error.log
    CustomLog /var/log/www/access.log common
</VirtualHost> и т.д.
Получал Cannot resolve host name....
Пришлось приручать DNS, с которым до сих пор борюсь... Но не в этом дело, вполне бы устроило заходить к примеру так:
http://192.168.0.1 - сайт и http://192.168.0.1/abills/ - биллинг (Что б не мучатся подымать днс, тем более что шлюз в сети не мой сервер)...
Думал зделать таким образом: путь к сайту описанный в апаче /usr/local/www/, в этом каталоге сам сайт и каталог abills (/usr/local/www/abills/) сам биллинг.
Набираем http://192.168.0.1 - попадаем на сайт, добавляем /abills/ - попадаем в биллинг.
Только вот как это скрутить всё в httpd.conf?
(Если учесть что у меня щас сайт лежит DocumentRoot /usr/local/www/joomla/, а биллинг DocumentRoot /usr/local/abills/cgi-bin/)
А за идею с SSL и настроенным DNS большое спасибо! Это будет следующими шагами для занятия в свободное время.

Re: Несколько сайтов (VirtualHost) на Apache

Добавлено: Вт июл 07, 2009 3:34 am
sopov
Ну тогда настройте по инструкции, там как раз ваш вариант.