Uživatelské nástroje

Nástroje pro tento web


linux-apache2-vhosts

Toto je starší verze dokumentu!


Apache2 a virtualhosts

default host

Abychom mohli mít pro každou virtuální doménu svůj konfigurační soubor, je třeba nadefinovat default hosta, na kterém další virtuální hosti budou. U default hosta budou jako u jediného klausule NameVirtualHost. U virtuálních hostů už toto nebude:

cat /etc/apache2/sites-available/default

NameVirtualHost *:80
<VirtualHost *:80>
        ServerName example.com
        ServerAdmin webmaster@example.com
        DocumentRoot /var/www/

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
        ServerSignature On
</VirtualHost>

virtuál host

Zde máme příklad prvního virtálního hosta

cat /etc/apache2/sites-available/01vhost <VirtualHost *:80>

  ServerAdmin webmaster@pklfkl.dyndns.org
  DocumentRoot /home/kviti/www
  ServerName kveta.pklfkl.dyndns.org
  ErrorLog /var/log/apache2/kveta-error.log
  CustomLog /var/log/apache2/kveta-access.log common

</VirtualHost>

Převzato z http://www.debianhelp.co.uk/virtualhosts.htm

 Example for name based virtual host in debian:-

Apache 2.0, the default site is instead the first file (in alphabetical order) in the /etc/apache2/sites-enabled directory. After initial installation, there will be a symlink from 000-default in this directory to /etc/apache2/sites-available/default. As you can see from this, Apache 2.0 offers another level of abstraction in the Virtual Hosts by recommending putting the actual files in /etc/apache2/sites-available and then symlinking from there to /etc/apache2/sites-enabled. I would recommend following this convention, but it's not mandatory. In our example above, we would create two files, /etc/apache2/sites-available/default and /etc/apache2/sites-available/example.com. Our /etc/apache2/sites-available/default file would look like this:

NameVirtualHost *
<VirtualHost *>
ServerName incorrect.com
DocumentRoot /home/www/html/default
</VirtualHost>

And our /etc/apache2/sites-available/example.com would look like this:

<VirtualHost *>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /home/www/html/example.com/html
CustomLog logs/www.example.com-access_log common
</VirtualHost>

We would then create symlinks to the /etc/apache2/sites-enabled directory with the ln -s

command: ln -s /etc/apache2/sites-available/example.com /etc/apache2/sites-enabled/example.com.

Now we have our Virtual Hosts configured, it's time to test. To start Apache 2, type /etc/init.d/apache2 start and fire up a browser and head to www.example.com

Example for IP based virtual host in debian:-

 /etc/apache2/sites-available/example.com would look like this:

<VirtualHost 192.168.1.20>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /home/www/html/example.com/html
CustomLog logs/www.example.com-access_log common
</VirtualHost>

We would then create symlinks to the /etc/apache2/sites-enabled directory with the ln -s

command: ln -s /etc/apache2/sites-available/example.com /etc/apache2/sites-enabled/example.com.

Now we have our Virtual Hosts configured, it's time to test. To start Apache 2, type /etc/init.d/apache2 restart and fire up a browser and head to www.example.com
linux-apache2-vhosts.1197838632.txt.gz · Poslední úprava: 2013/08/06 21:38 (upraveno mimo DokuWiki)