LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-14-2009, 08:36 AM   #1
phil333
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Rep: Reputation: 0
Apache2 configuration - www alias doesn't work


Hello,

I've some problems to configure Apache2
My server has a second IP address that I've added under /etc/network/interfaces with:
Code:
ip addr add
I can ping my server with this IP without any problems.

Now I want to configure a domain with this IP address on Apache2.
My domain is accessible with domain.tld but Apache shows me the standard website (if no defined rule matches) when browsing to www.domain.tld

My configuration under sites-enabled:
Code:
NameVirtualHost (IP):80
<VirtualHost (IP):80>
  ServerName domain.tld
  ServerAlias www.domain.tld
  DocumentRoot "/var/www/test"
</VirtualHost>
If I change the ServerAlias parameter to
Code:
  ServerAlias *.domain.tld
I can access the website trough every subdomain combination but not with www. The DNS entries should be right (A Record for www. and I get the same IP for ping domain.tld and www.domain.tld).

But I found out, that if I ping my server with "domain.tld" I get back as answer: www.domain.tld That's a different behaviour than pinging a domain that uses the server main IP (here I get back srv.myserver.tld which is the correct FQDN).

What is wrong in my configuration?
Hope somebody can help me.

Thank you
 
Old 10-14-2009, 09:06 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,526

Rep: Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503
Quote:
I can access the website trough every subdomain combination but not with www.
What happens then? Is anything written in error_log?
Your config is OK, but maybe it's worth trying the following syntax:
Code:
  ServerName www.domain.tld
  ServerAlias domain.tld *.domain.tld
 
Old 10-14-2009, 09:19 AM   #3
phil333
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
Your config is OK, but maybe it's worth trying the following syntax:
Code:
  ServerName www.domain.tld
  ServerAlias domain.tld *.domain.tld
I've tried your configuration, but I can still access the domain trough domain.tld and every subdomain (for example foo.domain.tld) but not with www.domain.tld.

Quote:
Originally Posted by bathory View Post
What happens then? Is anything written in error_log?
If no Apache rule is right apache displays the folder /htdocs. In this folder I've a .htaccess file that redirects to an 404 error.

So if I visit www.domain.tld I'm redirected to this 404 error file. This matches with /var/log/apache2/other_vhosts_access.log
Code:
www.domain.tld:80 153.96.x.x - - [14/Oct/2009:15:09:43 +0200] "GET / HTTP/1.0" 302 199 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3"
myserver.tld:80 153.96.x.x - - [14/Oct/2009:15:09:43 +0200] "GET /index.php?site=404 HTTP/1.0" 200 680 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3"
Additional I've added the following line in my sites-enabled config:
Code:
ErrorLog "/var/log/apache2/special-error.log"
CustomLog "/var/log/apache2/special-access.log"
If I access www.domain.tld no informations are written in these special log files. With other subdomain combination informations are written there
 
Old 10-14-2009, 09:39 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,526

Rep: Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503
Quote:
If no Apache rule is right apache displays the folder /htdocs. In this folder I've a .htaccess file that redirects to an 404 error.

So if I visit www.domain.tld I'm redirected to this 404 error file. This matches with /var/log/apache2/other_vhosts_access.log
Code:

www.domain.tld:80 153.96.x.x - - [14/Oct/2009:15:09:43 +0200] "GET / HTTP/1.0" 302 199 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3"
myserver.tld:80 153.96.x.x - - [14/Oct/2009:15:09:43 +0200] "GET /index.php?site=404 HTTP/1.0" 200 680 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3"
So you're using mod_rewrite or a redirect rule to redirect www.domain.tld to some kind of 404 error page?
From the logs I see that when you access www.domain.tld, you are redirected (note the 302 code in the 1st line), to myserver.tld/ndex.php?site=404 (2nd line code 200 means successful)
Isn't that what you want to achieve?
 
Old 10-14-2009, 09:52 AM   #5
phil333
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
So you're using mod_rewrite or a redirect rule to redirect www.domain.tld to some kind of 404 error page?
From the logs I see that when you access www.domain.tld, you are redirected (note the 302 code in the 1st line), to myserver.tld/ndex.php?site=404 (2nd line code 200 means successful)
Isn't that what you want to achieve?
The .htaccess file contains
Code:
Redirect / http://www.myserver.tld/index.php?seite=404
This redirection should only happen if a domain is accessed which is *not* described in the apache configs.

So if you look on my apache config again:
Code:
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
The displayed page of www.domain.tld should be the same as domain.tld (which is an existing website). So my problem is: If I visit domain.tld I get the correct website. If I visit www.domain.tld I get a redirection instead of the correct website. So this redirection is wrong. Apache acts like it doesn't know what to do for www.domain.tld although it is written in the configs
 
Old 10-14-2009, 10:11 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,526

Rep: Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503
Are you sure there is no other reference for www.domain.tld in apache config files?
I don't know how exactly apache works in distros like Debian, that use sites-available and sites-enable to define vhosts, but maybe you have to disable/re-enable vhosts and restart apache.
 
Old 10-14-2009, 10:31 AM   #7
phil333
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
Are you sure there is no other reference for www.domain.tld in apache config files?
I'm realy sure that there is no other configuration for this domain. If I search for this domain I get only the entries of this one config file.
Code:
# cat /etc/apache2/* | grep domain.tld  
cat: /etc/apache2/conf.d: Is a directory
cat: /etc/apache2/mods-available: Is a directory
cat: /etc/apache2/mods-enabled: Is a directory
cat: /etc/apache2/sites-available: Is a directory
cat: /etc/apache2/sites-enabled: Is a directory
cat: /etc/apache2/ssl: Is a directory
cat: /etc/apache2/suexec: Is a directory

# cat /etc/apache2/sites-available/* | grep domain.tld

# cat /etc/apache2/sites-enabled/* | grep domain.tld
  ServerName www.domain.tld
  ServerAlias domain.tld  *.domain.tld
Quote:
Originally Posted by bathory View Post
I don't know how exactly apache works in distros like Debian, that use sites-available and sites-enable to define vhosts, but maybe you have to disable/re-enable vhosts and restart apache.
I've restarted and reloaded apache after every config change. And I can check that the new configurations are realy used. If I remove *.domain.tld from ServerAlias for example, every subdomain.domain.tld is redirected to my 404 page.

Is there any other possibility that why the subdomain www is "locked"? That I get back www.domain.tld if I ping domain.tld can't be a problem?

I'll try to set a wildcard configuration for this IP, because there is only one domain at it at the moment. Lets see what happen...
 
Old 10-14-2009, 10:45 AM   #8
phil333
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
With this configuration
Code:
NameVirtualHost (IP):80
<VirtualHost (IP):80>
        DocumentRoot "/var/www/test/"
</VirtualHost>
I have access to the website with www.
However this shouldn't be a permanent solution. If somebody has any hints to solve my problem I would be glad to here them
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apache2 folder 'var/www' is not shareable; can not edit the index.html file mcanallyd Linux - Newbie 2 06-18-2009 06:46 PM
403 forbidden in Alias on apache2 TruthSeeker Linux - Server 2 06-17-2008 01:35 PM
why printer alias not work coolbud Linux - General 4 08-07-2006 05:29 PM
Printer alias does not work coolbud Linux - General 1 08-01-2006 08:37 PM
BIND www alias not working noir911 Linux - Networking 7 01-24-2006 04:54 AM


All times are GMT -5. The time now is 10:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration