LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Apache: Allowing IP Access and NameVirtualHost concurrently (https://www.linuxquestions.org/questions/linux-general-1/apache-allowing-ip-access-and-namevirtualhost-concurrently-476822/)

Swakoo 08-23-2006 10:38 PM

Apache: Allowing IP Access and NameVirtualHost concurrently
 
Hi guys,

I have always been using NameVirtualHost to manage multiple domains on one machine.

But, for a clean httpd.conf (no namevirtualhost specified), any access to the server will default to DocumentRoot yah?

But I realise I can't do that if NameVirtualHost is enabled. Anyway to allow both way of access?

haertig 08-24-2006 04:46 PM

I don't understand what your saying. I don't think the absense of a line "NameVirtualHost" makes httpd.conf all that much cleaner, but that's your call.

I have no trouble configuring Apache for both Virtual Hosting and also have a default DocumentRoot. I think that's what you're asking how to do. The first virtual host is your default host. Here's some cut/paste snippets from my httpd.conf showing bits and pieces of the setup. You can hit the three different hosts shown below like this (you can also hit one of the virtual host's files via the default host, I laid things out that way on purpose):
Code:

http://myhostname.domain.com
http://virthost1.domain.com
http://myhostname.domain.com:8000

Code:

NameVirtualHost *:80

<VirtualHost *:80>
    # Default
    ServerAdmin me@myemail.com
    ServerName myhostname.domain.com
    ServerAlias myotherhostname.domain.com
    DocumentRoot /web/apache2/htdocs
    # blah, blah, blah
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin theotherguy@email.com
    ServerName virthost1name.domain.com
    ServerPath /virthost1/
    DocumentRoot /web/apache2/htdocs/virthost1
    ErrorLog logs/virthost1-error_log
    CustomLog logs/virthost1-access_log common
    RewriteEngine on
    RewriteRule ^(/virthost1/.*) /web/apache2/htdocs$1
    # blah, blah, blah
</VirtualHost>

<VirtualHost _default_:8000>
    ServerAdmin yetanotherguy@email.com
    ServerName myhostname.domain.com
    ServerPath /port8000/
    DocumentRoot /web/apache2/htdocs/port8000
    ErrorLog logs/8000-error_log
    CustomLog logs/8000-access_log common
    ScriptAlias /cgi-bin/ "/web/apache2/htdocs/port8000/cgi-bin/"
    # blah, blah, blah
</VirtualHost>

Note: I cut/pasted my httpd.conf snippets and manually edited to generalize things. Hopefully I didn't make any typos in that manual editing, but I certainly could have. Use as an example only.

Swakoo 08-24-2006 09:19 PM

i'm sorry i am not clear enough. perhaps it is my lack of understanding on this issue - my apologies

What i'm looking at is to access the server via its IP (say http://192.168.1.10)
since we are still testing it. By accessing the server by that default IP, if there's nothing mentioned for DocumentRoot, it will show the Apache Test Page yah?
Let's say DocumentRoot in this case is /home/user

I then point beta.domain.com to it using NameVirtualHost (why am I doing this is because the actual domain.com is still pointing to another old server, doing migrating).
For this DocumentRoot, it will be in /home/user/beta


In this /home/user, there are other folders like /home/user/sql (phpMyAdmin), /home/user/other

so my question is: am I able to configure it such that I can access the server using the name (NameVirtualHost) http://beta.domain.com AND using the IP, http://192.168.1.10 and thus I can also access the other folders via http://192.168.1.10/sql etc...

Matir 08-25-2006 09:20 AM

As haertig said, set up your first NameVirtualHost to point to /home/user. Then any access will default to this host. Also, if there is no valid DocumentRoot, Apache will spit out an error, not the test page. (You haven't pointed it to the test page).

Swakoo 08-27-2006 10:46 PM

ah.. i got it to work already.. many thanks for the pointers!


All times are GMT -5. The time now is 05:09 AM.