Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sun Jan 18, 2009 10:46 am 
Offline
Senior Member

Joined: Sun Nov 30, 2008 3:40 pm
Posts: 109
I have a domain whose file are located at /var/www/vhosts/example.com/htdocs

When I try to access it with www.example.com, it opens fine. But when I try to access it without "www" it shows the contents of /var/www.

Any idea why?

Here's the content of /etc/apache2/sites-available/example.com
Code:
<VirtualHost *>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com

DocumentRoot /var/www/vhosts/example.com/htdocs

AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php

LogLevel warn
ErrorLog /var/www/vhosts/example.com/log/error.log
CustomLog /var/www/vhosts/example.com/log/access.log combined

</VirtualHost>


Last edited by dcelasun on Sun Jan 18, 2009 5:16 pm, edited 2 times in total.

Top
   
 Post subject:
PostPosted: Sun Jan 18, 2009 11:57 am 
Offline
Senior Member

Joined: Mon Sep 01, 2008 5:14 pm
Posts: 92
*edit* misread the question


Top
   
 Post subject:
PostPosted: Sun Jan 18, 2009 1:04 pm 
Offline
Senior Member

Joined: Sun Nov 30, 2008 3:40 pm
Posts: 109
I think I've found the problem, but not the solution. My hostname is set to "example.com" so the default configuration file in /etc/apache2/sites-available interferes with /etc/apache2/sites-available/example.com.

Here's the default file:
Code:
NameVirtualHost *
<VirtualHost *>
   ServerAdmin webmaster@localhost
   DocumentRoot /var/www

   <Directory />
      Options  Indexes FollowSymLinks MultiViews
      AllowOverride all
   </Directory>
         <Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      #Options -FollowSymLinks
      AllowOverride all
      Order allow,deny
      allow from all
      # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
               # RedirectMatch ^/$ /apache2-default/
   </Directory>

   ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">

      AllowOverride all
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all
   </Directory>

   ErrorLog /var/log/apache2/error.log

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

   CustomLog /var/log/apache2/access.log combined
   ServerSignature On

    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>


What should I change to make example.com (without www) work?


Top
   
 Post subject:
PostPosted: Sun Jan 18, 2009 4:18 pm 
Offline
Senior Member

Joined: Mon Jun 16, 2008 6:33 pm
Posts: 151
1) Are you sure you want your hostname set to example.com ?

2) Do you have DNS A records for both "www.example.com" and "example.com" pointing to your IP ?

3) Alternatively, remove the ServerAlias directive and create a second virtualhost setup for "example.com", with an .htaccess redirect to "www.example.com" (or vice versa). This is probably safer in the long term.


Top
   
 Post subject:
PostPosted: Sun Jan 18, 2009 5:06 pm 
Offline
Senior Member

Joined: Sun Nov 30, 2008 3:40 pm
Posts: 109
Thanks for the reply.

1) What else should I set it? I mean I have several domains there and should I set it to something that's not a domain? That would cause problems with spam blacklists because I send mail from these domains. Any suggestions?

2) Yes, I have them as they are automatically added by Linode's DNS manager when set as "master".

3) This seems like an ugly workaround, if there's an alternative I'd like to go with that.

------
Now, I've changed my hostname to something that doesn't make sense, like "whatever.com". This solved all my problems, but this is surely not the way to go. What can I do?


Top
   
 Post subject:
PostPosted: Sun Jan 18, 2009 5:16 pm 
Offline
Senior Member

Joined: Sun Nov 30, 2008 3:40 pm
Posts: 109
Ok, problem solved. I've created an A record for "server.example.com" and I've set my hostname to server.example.com as well. Now, there's no configuration file for server.example.com in /etcapache2/sites-available/, so the default config doesn't cause problems with any other config files.

Thanks for the help mjrich.


Top
   
 Post subject:
PostPosted: Sun Jan 18, 2009 6:48 pm 
Offline
Senior Member

Joined: Mon Jun 16, 2008 6:33 pm
Posts: 151
dcelasun wrote:
1) What else should I set it? I mean I have several domains there and should I set it to something that's not a domain? That would cause problems with spam blacklists because I send mail from these domains. Any suggestions?

The hostname needn't be related to mail -- use mailname (or some derivative if more than one domain).
Quote:
3) This seems like an ugly workaround, if there's an alternative I'd like to go with that.

Creating a second virtual host, redirecting to the first is the most reliable option (though I'd be interested if others have a more developed opinion). To paraphrase a faq at NFS, using both the bare domain and the www version without redirects creates issues such as:
  • Noncanonical URLs for your site. It is desirable to have one URL for each page, for purposes of bookmarking, etc. Having multiple valid URLs for the same page makes your site less popular in rankings and for search engines.
  • Potentially less reliable. DNS CNAME records cannot be used in this situation. You can put in a couple of A records, but this is still not as effective for load balancing and fault tolerance as doing it the "right" way.
  • It becomes hopelessly confusing if you have (or might ever have) more than one web site under the domain.
  • See also http://no-www.org

Quote:
Now, I've changed my hostname to something that doesn't make sense, like "whatever.com".

From your example, it seems as if you're trying to use a FQDN as a hostname, but surely this isn't the case (?)

Glad to hear it's all working though :)


Top
   
 Post subject:
PostPosted: Sun Jan 18, 2009 6:55 pm 
Offline
Senior Member

Joined: Sun Nov 30, 2008 3:40 pm
Posts: 109
Currently, it is set to "server.example.com", which is an FQDN, so everything is fine.

I'll also set an htaccess redirect for www, I now understand your points. Thanks for pointing them out!


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group