Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I created new virtual host, but when I try to request it, Apache redirects me to another virtual host. What could cause this problem?

<VirtualHost XXX.XXX.XXX.XXX:80 >
    ServerName domain1.com
    AddDefaultCharset utf-8
    CustomLog /var/www/httpd-logs/domain1.com.access.log combined
    DocumentRoot /home/user/www/domain1.com
    ErrorLog /var/www/httpd-logs/domain1.com.error.log
    ServerAdmin admin@myemail.com
    ServerAlias www.domain1.com
    SuexecUserGroup user user
    AddType application/x-httpd-php .php .php3 .php4 .php5 .phtml
    AddType application/x-httpd-php-source .phps
    php_admin_value open_basedir "/home/user:."
    php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f admin@myemail.com"
    php_admin_value upload_tmp_dir "/home/user/mod-tmp"
    php_admin_value session.save_path "/home/user/mod-tmp"
    ScriptAlias /cgi-bin/ /home/user/www/domain1.com/cgi-bin/
</VirtualHost>

<VirtualHost XXX.XXX.XXX.XXX:80 >
    ServerName domain2.com
    CustomLog /dev/null combined
    DocumentRoot /home/user/www/domain2.com
    ErrorLog /dev/null
    ServerAdmin admin@myemail.com
    ServerAlias www.domain2.com
    SuexecUserGroup user user
    AddType application/x-httpd-php .php .php3 .php4 .php5 .phtml
    AddType application/x-httpd-php-source .phps
    php_admin_value open_basedir "/home/user:."
    php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f admin@myemail.com"
    php_admin_value upload_tmp_dir "/home/user/mod-tmp"
    php_admin_value session.save_path "/home/user/mod-tmp"
</VirtualHost>

"apache2ctl -S" output:

VirtualHost configuration:
XXX.XXX.XXX.XXX:80 is a NameVirtualHost
         default server domain1.com (/etc/apache2/apache2.conf:266)
         port 80 namevhost domain1.com (/etc/apache2/apache2.conf:266)
         port 80 namevhost domain2.com (/etc/apache2/apache2.conf:284)
XXX.XXX.XXX.XXX:443      is a NameVirtualHost
         default server domain1.com (/etc/apache2/apache2.conf:246)
         port 443 namevhost domain1.com (/etc/apache2/apache2.conf:246)
wildcard NameVirtualHosts and _default_ servers:
*:443                  is a NameVirtualHost
         default server www.example.com (/etc/apache2/apache2.conf:239)
         port 443 namevhost www.example.com (/etc/apache2/apache2.conf:239)
*:80                   is a NameVirtualHost
         default server domain1.com (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost domain1.com (/etc/apache2/sites-enabled/000-default:1)
share|improve this question
    
Do you mean that it's sending a redirect response (so that the address bar in the browser changes), or that it's serving the content from the other domain without the address bar changing? –  Shane Madden Sep 10 '12 at 6:18
    
It's not redirect response, just shows content from the first virtual host, when i request second. This is obviously a problem with apache configuration, but when I restart Apache, it doesn't show me any error and the code generated for virtual hosts by ISPManager, I didn't change anything there. –  Dmitry Mikhaylov Sep 10 '12 at 15:39
    
Gotcha, sounds like it's just serving the wrong vhost. Can you provide the output from apachectl -S? –  Shane Madden Sep 10 '12 at 15:45
    
@ShaneMadden, did it. –  Dmitry Mikhaylov Sep 17 '12 at 16:30
    
So you're getting domain1's content instead of domain2? Do you know whether it's the copy of domain1 that's configured in /etc/apache2/sites-enabled/000-default, or the one from /etc/apache2/apache2.conf line 266? –  Shane Madden Sep 17 '12 at 18:34
show 3 more comments

1 Answer 1

Have you added

NameVirtualHost *:80

to your config?

share|improve this answer
    
Yes, there is a record NameVirtualHost in config files. I didn't add it actually, it was automatically created by ISPManager panel. –  Dmitry Mikhaylov Sep 8 '12 at 18:29
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  EEAA Sep 8 '12 at 22:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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