LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Apache subdomain help (https://www.linuxquestions.org/questions/linux-newbie-8/apache-subdomain-help-771261/)

Orange Sunshine 11-24-2009 11:45 AM

Apache subdomain help
 
It may make more sense for me to post this in an Apache forum but I have gotten really great help from this community recently so I figured I'd try here first.

I am running CentOS 5 and Apache 2.2.3 and I am trying to set up a subdomain. I have read several web pages on the matter and tried several different things with no success. I have custom DNS set up at dyndns.com and before I started messing with subdomain stuff everything was working fine. For these purposes we'll say my domain is mydomain.net and I want the subdomain to be admin.mydomain.net. Here is what my /etc/hosts file looks like:

#Start File ----
127.0.0.1 mydomain.net localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
127.0.0.1 admin.mydomain.net
#End File ----

...and here are the changes I made to /etc/httpd/conf/httpd.conf:

I uncommented NameVirtualHost *:80

and added this to the end of the file:

<VirtualHost *:80>
DocumentRoot /var/www/admin
ServerName admin.mydomain.net
ServerAlias admin.mydomain.net
</VirtualHost>


I then created a directory called "admin" in /var/www and put a simple hello world php file there. Now on the internet when I go to admin.mydomain.net I get Server not found "Firefox can't find the server at admin.mydomain.net." and when I go to mydomain.net I get the hello world that I put in the admin directory.

Again, before I started messing with this subdomain business I could go to mydomain.net and it would show the website just fine. What am I doing wrong?!?

As always, help is greatly appreciated!

Thanks!

rweaver 11-24-2009 01:41 PM

You also need to declare a virtualhost for your main domain.

Orange Sunshine 11-24-2009 02:01 PM

Quote:

Originally Posted by rweaver (Post 3768246)
You also need to declare a virtualhost for your main domain.

Okay, I added a VirtualHost for my main domain as well so now the end of the httpd.conf file looks like this:

<VirtualHost *:80>
DocumentRoot /var/www/admin
ServerName admin.mydomain.net
ServerAlias admin.mydomain.net
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName mydomain.net
ServerAlias mydomain.net
</VirtualHost>


I restarted Apache and I still get the same issue. Server not found at admin.mydomain.net and the /var/www/admin/index.php file when I go to mydomain.net instead of the /var/www/html/index.php file I am expecting.

Also, I posted here http://www.apacheforum.com/showthread.php?t=167605 for additional help from some apache uses.

Orange Sunshine 11-24-2009 03:11 PM

Okay, I think I've made some progress...kinda. I moved my admin directory from /var/admin to /var/www/html/admin

Now when I visit mydomain.net I get the index.php file in /var/www/html like I want/expect and when I visit mydomain.net/admin I get the index.php file in /var/www/html/admin like I guess I would expect. So how do I get admin.mydomain.net to serve me the /var/www/html/admin/index.php like I want? I still get a Server Not Found error when I try to visit admin.mydomain.net.

...by the way, the forum at http://www.apacheforum.com/ is so flooded with spam that I don't see myself getting any help there. Is there another forum you guys would suggest I post to for Apache help?

neeraj_sriva 11-24-2009 03:23 PM

Is your subdomain resolving ? What you get when you run nslookup admin.mydomain.net ?

Orange Sunshine 11-24-2009 03:33 PM

Quote:

Originally Posted by neeraj_sriva (Post 3768348)
Is your subdomain resolving ? What you get when you run nslookup admin.mydomain.net ?

when I type admin.mydomain.net under nslookup I get:

Server: 208.67.222.222
Address: 208.67.222.222#53

Non-authoritative answer:
Name: admin.mydomain.net
Address: xx.xxx.xxx.xxx

and then when I type mydomain.net (which is resolving fine) under nslookup I get:

Server: 208.67.222.222
Address: 208.67.222.222#53

Non-authoritative answer:
Name: mydomain.net
Address: xx.xxx.xxx.xxx


I have no idea what the 208.67.222.222 addresses are but the xx.xxx.xxx.xxx are matching for both and are the correct ip address to my machine. Does that mean it is resolving correctly? Also, I did the nslookup on the web server that is hosting the site. Is that what I was supposed to do? Or do I need to do it on another machine?

Orange Sunshine 11-24-2009 03:38 PM

Quote:

Originally Posted by Orange Sunshine (Post 3768358)
Also, I did the nslookup on the web server that is hosting the site. Is that what I was supposed to do? Or do I need to do it on another machine?

Just to be sure I tried it on another machine and I got the same results for Non-Authorative answer but different addresses for the first Server:
Address: if that makes any sense.

neeraj_sriva 11-24-2009 04:03 PM

The ip should match at the machine where you are opening your website in Firefox, if both sub domain and main domain are hosted on same IP. Also, check if you can open your page at web server itself, if it is working there then some problem with name resolution at other machine.

Orange Sunshine 11-24-2009 04:10 PM

Quote:

Originally Posted by neeraj_sriva (Post 3768392)
The ip should match at the machine where you are opening your website in Firefox, if both sub domain and main domain are hosted on same IP. Also, check if you can open your page at web server itself, if it is working there then some problem with name resolution at other machine.

Well, something magic happened and everything is working correctly now. I didn't make any changes at all since the last time I checked and it wasn't working. Oh well, I'm not complaining.

Thanks for the help!


All times are GMT -5. The time now is 11:46 PM.