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 have a server with IP 1.2.3.4 and I want the domain www.something.com to load website from /var/www/html/something/

I've tried to configure them as follows:

NameVirtualHost 1.2.3.4:80

<VirtualHost 1.2.3.4:80>

ServerName www.something.com
ServerAdmin emai@email.com
DocumentRoot /var/www/html/something/
ErrorLog logs/something-error_log
CustomLog logs/something-access_log common
</VirtualHost>

I've reloaded apache, but when accesing the domain, it only shows the root of the server /var/www/html/

Any idea what is wrong?

share|improve this question

migrated from stackoverflow.com Oct 26 '12 at 12:52

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 0 down vote accepted

A common mistake is to set the IP address in VirtualHost and NameVirtualHost without good reason.

Instead, your config should read:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName www.something.com
  ServerAdmin emai@email.com
  DocumentRoot /var/www/html/something/
  ErrorLog logs/something-error_log
  CustomLog logs/something-access_log common
</VirtualHost>
share|improve this answer
    
I've tried this method, but then 1.2.3.4 points to /var/html/something/ also! –  Tomiţă Militaru Oct 26 '12 at 10:18
    
If you start using NameVirtualHosting then you should stop using IP addresses. To work around this, add another VirtualHost with no ServerName definition to the bottom if your httpd.conf. –  Alastair McCormack Oct 26 '12 at 10:22
    
Thanks! That was the issue. –  Tomiţă Militaru Oct 26 '12 at 10:23
1  
I've just found this: wiki.apache.org/httpd/CommonMisconfigurations that you might find useful –  Alastair McCormack Oct 26 '12 at 10:24

Your Answer

 
discard

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