0

I started virtual host on my VPS,

I am having two websites on it, one which was already there and the second which I trasferred now, But before changing the name-servers of the new transfered wordpress site, I want to test it. How can I check it, whether its working with no errors, or some errors are there?

When I type my IP address of the VPS I get my old website, if I type http://ip/new_site_folder_name I get 404, no such page found

My virtual host config is this:

    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /var/www/html/www.mbas.co.in
    ServerName mbas.co.in
    ErrorLog logs/mbas.co.in-error_log
    CustomLog logs/mbas.co.in-access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /var/www/html/onlinemba123
    ServerName onlinemba123
    ErrorLog logs/onlinemba123-error_log
    CustomLog logs/onlinemba123-access_log common
</VirtualHost>
Niraj Chauhan
  • 252
  • 2
  • 13
  • If you use the IP addy, you'll always get the first vhost Apache is configured for; your second vhost has an *interesting* hostname, you're entering `http://onlinemba123` into your browser and have that exact hostname mapped in your hosts file? – Chris S Feb 10 '11 at 13:36
  • @Chris S so in ServerName I have to change from onlinemba123 to http://onlinemba123 Am I rite? – Niraj Chauhan Feb 10 '11 at 15:53
  • ServerName should be exactly what you enter into the address bar *after* `http://` and *before* `/whatever/page.html`. – Chris S Feb 10 '11 at 15:57
  • @Chris S I enter exactly same, but one more thing, do I have to set DNS settings?, cause I haven't till yet – Niraj Chauhan Feb 10 '11 at 16:05
  • @Ntechi, you don't have to change DNS. There must be something else in your configuration file that's messing this up. What you have above is syntactically correct. – Chris S Feb 10 '11 at 16:13
  • @Chris S then why am I getting Centos Default page instead of my website, where as my other website is working fine – Niraj Chauhan Feb 10 '11 at 16:16
  • If neither of those directories have the default page in them, someone else in the configuration file is hosed. ;) – Chris S Feb 10 '11 at 16:18
  • @Chris S so what should I do now? – Niraj Chauhan Feb 10 '11 at 16:23
  • Start looking over the rest of the configuration file(s). I'm not good with CentOS, so I'm not sure how many files there are or where they're located, but most Linux distros have Apache divided up into several sections. – Chris S Feb 10 '11 at 16:24
  • @Chris S no any other solution rather then this? OK I ll see to it – Niraj Chauhan Feb 10 '11 at 16:29

2 Answers2

1

You have to use the form http://new_site.co.in, the folder name is irrelevant because it will become the root folder of your site.

Edit - Explanation of vhosts

Based on your comments, I don't think you understand how virtual hosts in Apache work.

First, both domains (old_site.co.in and new_site.co.in) must point to the IP of your machine (this is a DNS thing). With the site definitions your wrote in your post, you will then tell apache to serve the contents of /html/www.old_site.co.in when a browser tries to open http://www.old_site.co.in and the contents of /html/www.new_site.co.in if the browser asks for http://www.new_site.co.in. This works even if both domains have the same IP address because the site name is transferred in the HTTP request.

Sven
  • 98,649
  • 14
  • 180
  • 226
  • I agree. The http://ip/new_site_folder_name scheme is not a function of apache. It's frequently part of some control panel software (such as Plesk, or cPanel), but it does not exist on a default apache installation on CentOS. – Joe Feb 09 '11 at 11:48
  • but my folder name is same as my domain name, which is pointing somewhere, so that website will open, any other way? And if I change the folder name, and then type on url http://new_site.com, will it get opened? I think their will be no such site with this name, so it will return 404 – Niraj Chauhan Feb 09 '11 at 11:50
  • Why don't you just try it? Also, see my edit for an explanation of how this works. – Sven Feb 09 '11 at 12:02
  • OK in my DNS, I have added everything, and I also changed the folder name, but now when I type new_named_site, I get server not found – Niraj Chauhan Feb 09 '11 at 12:12
  • This might be because DNS entries might take a while before propagating. Try the command `nslookup new_site.co.in` to see if your DNS entry is correct. – Sven Feb 09 '11 at 12:24
  • I am getting this, when I typed nslookup `Server: 89.36.21.42 Address: 89.36.21.42#53 ** server can't find onlinemba123: NXDOMAIN ` – Niraj Chauhan Feb 09 '11 at 12:30
  • Because `onlinemba123` is not a valid domain name without a TLD suffix (like .com, .org or .co.uk). – Sven Feb 09 '11 at 12:36
1

It looks like you've already changed your DNS, which is fine. But I wanted to mention that if you want to test your virtual host configuration before messing with the DNS settings (useful if you want to keep an old site live while you get everything ready on the new host) you can temporarily make the change in your hosts file on your local computer and the change will take effect immediately.

matthew
  • 1,319
  • 1
  • 11
  • 21
  • in hosts file, what IP should I write 127.0.0.1 or the current VPS IP? – Niraj Chauhan Feb 09 '11 at 12:50
  • On the computer your testing from (the workstation you're sitting at) edit the hosts files and put in `[ip_of_server] old_site.co.in`. Test (with a browser on your computer). Then remove the line. – Chris S Feb 09 '11 at 13:55
  • @Chris S, I tried that, when I enter in URL, then my old site is opening, instead of the new one, why so – Niraj Chauhan Feb 09 '11 at 14:13
  • Correcting your configuration is outside the scope of the original question. This isn't a forum for ongoing discussions. From the Apache documentation "the argument to VirtualHost must match the argument to NameVirtualHost" – Chris S Feb 09 '11 at 14:20
  • @Chris S I didn't get you, Is there anything wrong with my virtual host config? – Niraj Chauhan Feb 09 '11 at 15:43
  • @ntechi yes your config is slightly off. Apache doesn't know how to get to the new site which is why it defaulting to the old. The VirtualHost tags should be the same for both and should be bound to *:80. Like this – matthew Feb 09 '11 at 18:21
  • @mathew I did as per your saying, but now when I type new_website on url, I am getting the default "Apache 2 Test Page" , and my old website is working well, now my config is changed, check my question – Niraj Chauhan Feb 10 '11 at 08:42
  • I think we're beyond the scope of the original question.Based on what I see of your config if you use onlinemba123 as the domain in your url you'll get to the second virtual host. If you use any other domain you'll get to first virtual host. However if you are getting somewhere else it means there's some other part of your config that's taking over. – matthew Feb 10 '11 at 19:05