2012年3月20日 星期二

[How-to] Add Virtual Host using different port in apache

This article teaches you how to create multiple websites in an apache server by using different port.
In this example, we use port 80 and 90.

1. Update /etc/apache2/ports.conf
Add the following lines in the file
NameVirtualHost *:80
Listen 80  
NameVirtualHost *:90
Listen 90

2. Update /etc/apache2/sites-available/default
Copy and paste the <VirtualHost *:80> content and make changes as follow


<VirtualHost *:80>
   ...
</VirtualHost>
<VirtualHost *:90>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www_anothersite
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www
_anothersite/>
        Options Indexes 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 ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>


3. Create the corresponding folder for the new website (port 90)
mkdir /var/www_anothersite

4. Done and test

沒有留言:

張貼留言