I've been struggling with Apache Virtualhost for a day now. I would like to run 2 sites with one ip.

When I enter the address in the url bar(domain1 or domain2), it always shows the default page only(which is domain1).

Any help will/would be appreciated...

My configuration :





├── domain1.conf -> ../sites-available/domain1.conf

└── domain2.conf -> ../sites-available/domain2.conf

domain2.conf :

<VirtualHost *:80>

    ServerName www.domain1.tk
    ServerAlias domain1.tk
    DocumentRoot /var/www/html/domain1/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


domain2.conf :

<VirtualHost *:80>

    ServerName domain2.tk
    ServerAlias www.domain2.tk
    DocumentRoot /var/www/html/domain2/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


apache2.conf :

Mutex file:${APACHE_LOCK_DIR} default

Timeout 300
KeepAlive On

MaxKeepAliveRequests 100
KeepAliveTimeout 5


HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf
  • Please improve your formatting. And first a dumb question: Did you disable the default site?
    – rda
    Jun 7, 2016 at 12:14
  • Add the output of apachectl -S
    – rda
    Jun 8, 2016 at 10:06
  • It's working now.
    – jan
    Jun 10, 2016 at 13:19

1 Answer 1


When I lookup your domains, I get 2 different IP addresses. In this case your configuration needs to be something like this:

# This is the "main" server running on IP_ADDRESS_OF_DOMAIN_tsk-run.tk
ServerAdmin webmaster@tsk-run.tk
ServerName tsk-run.tk
ServerAlias www.tsk-run.tk
DocumentRoot /var/www/html/tsk-run/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<VirtualHost IP_ADDRESS_OF_DOMAIN_tsk-test.tk>
    ServerAdmin webmaster@tsk-test.tk
    ServerName tsk-test.tk
    ServerAlias www.tsk-test.tk
    DocumentRoot /var/www/html/tsk-test/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Replace IP_ADDRESS_OF_DOMAIN_tsk-test.tk with the IP address of this domain.

See apache documentation section Name-based hosts on more than one IP address for more details.

  • Thank you. It's working now, but it put me on the root('html') page. Anyway, you've helped me a lot already...
    – jan
    Jun 7, 2016 at 17:14
  • @jan what dou mean with root('html') page?
    – rda
    Jun 7, 2016 at 18:29
  • I mean I'm in the "Main DocumentRoot('/var/www/html') instead of '/var/www/html/tsk-run.tk/public_html' .
    – jan
    Jun 8, 2016 at 4:36
  • There was an another mistake by me. The domain was pointing on wrong place. But I couldn't make it without your help. Cheers. :)
    – jan
    Jun 10, 2016 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.