LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache: virtual host issue (https://www.linuxquestions.org/questions/linux-server-73/apache-virtual-host-issue-509854/)

Zeno McDohl 12-12-2006 06:40 PM

Apache: virtual host issue
 
I have a server I pay for, and one I run. My biyg.org points to the server I pay for. I want fwarlords.biyg.org (and only that) to point to a certain folder (fwarlords) on the server I run. Here is what I have in the httpd.conf:

Code:

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/fwarlords"
ServerName fwarlords.biyg.org
<Directory "/opt/lampp/htdocs/fwarlords">
allow from all
Options +Indexes
</Directory>
</VirtualHost>

But it's wrong. If you go to zeno.biyg.org which should point to the server I run (the index site) it still points to the fwarlords folder for some reason. How can I fix this?

Wim Sturkenboom 12-12-2006 10:47 PM

My understanding of apache:
It looks in the virtualhost section for the servername (fwarlords......).
Next it takes the associated document root and looks in there for the pages. And the associated document root refers to the system where apache is running (so the server that you pay for).

I might, however, be totally wrong.

The only way I see is that you mount the directory of your own server on the server that you pay for. Wonder if your hosting provider allows this.
As an alternative, you can create an index page on the server that you pay for and let that redirect the visitor to the site on your own server; this is however not as neat.

Zeno McDohl 12-12-2006 11:28 PM

I'm pretty sure it can be done, there are examples I seem to have seen but can't remember offhand at this time. Oh and I forgot to mention, the domain (biyg.org) is set to the nameserver of my paid server. That's what I mean by "pointing to the server I pay for".

mrJimmbo 12-13-2006 01:13 AM

Could it be the zone records in the name server that hosts the domain biyg.org?

If the name server doesn't know where to direct the subdomain to there could be problems...

Zeno McDohl 12-13-2006 11:58 AM

You're telling me I have to talk to my paid hosting server every time I want to make a new subdomain (that I own) that points to my own server?

trickykid 12-13-2006 12:10 PM

Remember, from your main server configuration in httpd.conf, when creating a VirtualHost, you'll also need a configuration for your main domain, when creating a subdomain.

Make you're original look like this:

Code:

NameVirtualHost *:80

<VirtualHost *>
  DocumentRoot "/opt/lampp/htdocs/"
  ServerName biyg.org
  ServerAlias *.biyg.org
    <Directory "/opt/lampp/htdocs/fwarlords">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

<VirtualHost *>
  DocumentRoot "/opt/lampp/htdocs/fwarlords"
  ServerName fwarlords.biyg.org
    <Directory "/opt/lampp/htdocs/fwarlords">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

Make the necessary changes for actual file paths but it should look something like that. And you don't necessarily need to specify the port in the VirtualHost tag if the default is already 80. And you might not need the <Directory> tags for your main domain of biyg.org either, but like I said, mine is just an example of what should work.

Plus after making changes, you need to restart apache for the configs to be reread. You can run a configtest to test the configuration before restarting to prevent any failures if the configs won't work and then your site is unaccessible.

Zeno McDohl 12-13-2006 05:33 PM

That looks right (the paths), so here's what I put in:
Code:

NameVirtualHost *:80

<VirtualHost *>
  DocumentRoot "/opt/lampp/htdocs/"
  ServerName biyg.org
  ServerAlias *.biyg.org
</VirtualHost> 

<VirtualHost *>
  DocumentRoot "/opt/lampp/htdocs/fwarlords"
  ServerName fwarlords.biyg.org
    <Directory "/opt/lampp/htdocs/fwarlords">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

I get this warning on restarting Apache:
Quote:

[Wed Dec 13 19:24:27 2006] [warn] NameVirtualHost *:80 has no VirtualHosts
But now if you go to fwarlords.biyg.org or zeno.biyg.org, both point to the index. Fwarlords should bring you to the fwarlords folder, but no longer does.

trickykid 12-13-2006 05:51 PM

What version of Apache are you running? Try adding the *:80 in the <VirtualHost> tags for each VirtualHost.

trickykid 12-13-2006 05:53 PM

I just tested both of these domains and they both seem to resolve to different pages. From this end I would assume they are working.

Zeno McDohl 12-13-2006 06:50 PM

Really? zeno.biyg.org takes you to a different page than fwarlords.biyg.org? It doesn't for me. I just talked to a friend, he also says both pages take him to the same page (which is wrong).

Apache version 1.3.33, adding that :80 part fixes the warning but not the sites.

trickykid 12-13-2006 09:10 PM

Quote:

Originally Posted by Zeno McDohl
Really? zeno.biyg.org takes you to a different page than fwarlords.biyg.org? It doesn't for me. I just talked to a friend, he also says both pages take him to the same page (which is wrong).

Apache version 1.3.33, adding that :80 part fixes the warning but not the sites.

Oh wait. I tested fwarlords.biyg.org and just biyg.org, which take you to different pages. If you need zeno.biyg.org to go to a different page, you have to also create a VirtualHost for it as well.

Zeno McDohl 12-13-2006 09:36 PM

Oh, okay. Because biyg.org has nothing to do with what we're doing here.

But uh... zeno.biyg.org goes to the right page, fwarlords.biyg.org does not. Even though I already have a VirtualHost (like you told me to do) for that. Right now fwarlords.biyg.org points to /opt/lampp/htdocs/ instead of /opt/lampp/htdocs/fwarlords

Zeno McDohl 12-16-2006 10:07 PM

I might not be clear, since there seems to be some misunderstanding.

ServerA: A webserver host I am paying for.
ServerB: My own server (located in my room).
Domain: I own the biyg.org domain. The domain uses ServerA's nameserver.

Both fwarlords.biyg.org and zeno.biyg.org need to point to ServerB. Which they do. fwarlords.biyg.org needs to point to /opt/lampp/htdocs/fwarlords on ServerB, while zeno.biyg.org needs to point to /opt/lampp/htdocs/ on ServerB. wwww.biyg.org has nothing to do with this.

With this:
Code:

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot "/opt/lampp/htdocs/"
  ServerName biyg.org
  ServerAlias *.biyg.org
</VirtualHost> 

<VirtualHost *:80>
  DocumentRoot "/opt/lampp/htdocs/fwarlords"
  ServerName fwarlords.biyg.org
    <Directory "/opt/lampp/htdocs/fwarlords">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

It doesn't fully work. Both zeno.biyg.org and fwarlords.biyg.org both point to /opt/lampp/htdocs/fwarlords on ServerB.

s1m.com 12-19-2006 03:57 PM

mrJimmbo has identified your problem. Requests for biyg.org go to the server at your paid hosting service. The DNS server there needs to know where to direct subdomain requests. This is ususally done by adding a "A" record.

Zeno McDohl 12-19-2006 09:34 PM

I already have A records for both subdomains, they both point to ServerB's IP. Is that correct?

Zeno McDohl 12-21-2006 01:31 PM

Since it brings the subdomains to ServerB, I assume it's fine. The problem is probably in the conf file which is why I asked in the first place.

phil.d.g 12-21-2006 01:41 PM

Code:

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot "/opt/lampp/htdocs/zeno"
  ServerName zeno.biyg.org
    <Directory "/opt/lampp/htdocs/zeno">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "/opt/lampp/htdocs/fwarlords"
  ServerName fwarlords.biyg.org
    <Directory "/opt/lampp/htdocs/fwarlords">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

That ought to do the trick.

Note: this is trickykid's example with one or two lines changed.

ETA: The first virtual server defined is the default.

Zeno McDohl 12-21-2006 02:59 PM

Thanks, I had to change a bit but that worked. Thanks again.


All times are GMT -5. The time now is 03:10 AM.