Subdomains in apache

Hello,

I know this has probably been covered numerous times, however, none of the solutions I've found on the forums here have worked for me.

As you can most likely gather, I cannot get my subdomains with Apache working. I'm running a Ubuntu Lucid server, or 10.04. I'm pretty new to this whole Linux stuff, so, it shouldn't be too difficult. I just can't find what's going on.

Anyway, as:

This Linode Library Link

assisted me in getting the Apache2 server set up. I followed it as closely as I can. Put my IP address into the ports.conf file, and disabled the default site, and created the two domain virtual host files. The only area in which I dictated were where I wanted to store the files and the actual domain names. One of which, I wish to be a subdomain of the main domain.

I will paste the Virtual host files below:

The first one is for my main domain, tjsquires.net, which works fine:

ServerAdmin tj@tjsquires.net

ServerName tjsquires.net

ServerAlias http://www.tjsquires.net

DocumentRoot /home/tjsquires/tjsquiresnet

ErrorLog /home/tjsquires/tjsquiresnet/logs/error.log

After creating this one, I went into Linode's DNS manaager and set up a CName alias, games, that links to my IP. That didn't work, so I tried an A record. None of them worked. They both when going to games.tjsquires.net, linked back to my main homepage. here's the virtual host file for the games subdomain:

ServerAdmin tj@tjsquires.net

ServerName games.tjsquires.net

ServerAlias http://www.games.tjsquires.net

DocumentRoot /home/tjsquires/games.tjsquires.net

ErrorLog /home/tjsquires/games.tjsquires.net/logs/error.log

Am I doing something completely wrong here? The linux Newbie needs your help! :)

Thank you,

Tj

15 Replies

@tjsquires:

Am I doing something completely wrong here? The linux Newbie needs your help! :)

At this point, I'm not seeing anything in DNS for brianna.tjsquires.net or www.brianna.tjsquires.net, so check on that first.

You said at one point you had the DNS working, but it pulled up your main host instead of the right virtualhost. Dumb question, did you restart apache after making the config change?

Hi,

Whoops. When tinkering with it last night I did remove my DNS entry and have just now re-added it. I added it as a CNAME alias as I have been instructed to do as to some guides I've read.

I can redo it to an A record if need be, however, I've done this before and no luck

Yes. I have reloaded, and even restarted, apache. I will do that now again just to be safe.

It saw no errors with the config files and seems to have been restarted successfully. To cover all my bases, I reloaded apache's settings with /etc/init.d/apache2 reload as well.

Tj

Does /etc/apache2/ports.conf have a "NameVirtualHost" entry, like

NameVirtualHost *:80

edit: I guess in your case it should be

NameVirtualHost 173.230.152.119:80

Hi,

Here is my ports.conf file. In the guide I read it said to replace some lines with my IP, which I have done. Is this where the problem lies? File is below.

If you just change the port or add more ports here, you will likely also

have to change the VirtualHost statement in

/etc/apache2/sites-enabled/000-default

This is also true if you have upgraded from before 2.2.9-3 (i.e. from

Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and

README.Debian.gz

NameVirtualHost 173.230.152.119:80

Listen 80

# If you add NameVirtualHost *:443 here, you will also have to change

the VirtualHost statement in /etc/apache2/sites-available/default-ssl

to # Server Name Indication for SSL named virtual hosts is currently not

supported by MSIE on Windows XP.

Listen 443

Listen 443

Since something similar came up recently, have a gander at this:

http://forum.linode.com/viewtopic.php?t=7031&highlight=

maybe it helps…

Hi,

I had a look at that other post. My cache is turned off, and I've had several other people test out the subdomain to no luck. I looked at the name based virtual host documentatiot and the virtual hosts look like I believe they should. See my first post if you need to see them. I know I'm going to feel like an idiot once this is figured out, but…at least I'll learn something. I do wonder though if there is issues with the files in /etc/apache2/sites-available. Are they not even beeing looked at properly? I guess what I'm trying to get at is when someone types in my subdomain, the http headers are only catching the main domain portion. I'm just guessing here. I'm completely baffled as to why this is happening. It all looks right to me, but, apparently, it isn't yet. :) Oh. I should state that, include /etc/apache2/sites-enabled is indeed in the apache2.conf file.

Thanks again for all of your effort. A linux newbie really really does opretiate it.

Tj

The subdomain brianna.tjsquires.net resolves to your server, so the problem is not with DNS; it is with your virtual host configuration.

Beyond that, in a measure of desperation, what happens if you disable the main virtual host (www.tjsquires.net) with a2dissite ? (and reload apache) What does your /etc/apache2/sites-enabled/000-default file look like?

Now I'm slightly getting somewhere:

I have disabled tjsquires.net via sudo a2dissite tjsquires.net

Then I reloaded apache: sudo /etc/initd/apache2 reload

It gives me an error saying no virtual hosts are loaded. So, to cover my base:

sudo a2ensite brianna.tjsquires.net

It tells me that site is already loaded. So it looks to me as if something's not being seen somewhere.

I go to /etc/apache2/sites-enabled and see that brianna.tjsquires.net is deffinetly there. Just to check, I go to sites-available. all of my sites are there too.

So why would it be having trouble loading the brianna.tjsquires.net file if apache says it's enabled?

Thanks,

Tj

When you do a2ensite and it says a host is already loaded, that just means there is a symlink from the sites-enabled directory to the actual file in the sites-available directory. It says nothing of Apache actually load the vhost files at startup. Do you still get the error message about no virtual hosts loaded when you restart apache, and what is the exact text of that error message?

Go into /etc/apache2 and run this:

grep -rli "namevirtualhost" *

just to see if you have multiple namevirtualhost lines anywhere in your config.

I am just editing over another post. It says I've got one in ports.conf and one in apache2.conf.

Do I need to remove one of them, or change the one in apache2.conf to look the same as my ports.conf line?

Ideally you should only have one. Try commenting the one in apache2.conf.

Hi,

That did the trick. Thanks a bunch for all of your help.

I suppose the lesson of the day is to read, re-read, and still re-read, the conf files, eh? Also, I believe that command will come in extremely handy.

Thanks again for all of the help I've been given - it's really opretiated.

It's always something different.

BTW both your main domain and subdomain are still showing the same content for me; are you positive it is working now?

Yes. It works. I have taken the subdomain down so I can configure it so she can upload through her own user.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct