LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache - VirtualHost setting not working? (https://www.linuxquestions.org/questions/linux-server-73/apache-virtualhost-setting-not-working-518207/)

Splenden 01-10-2007 08:23 PM

Apache - VirtualHost setting not working?
 
Hi,

I just set up my Apache configuration file, and I added a VirtualHost (IP-based) for one domain that I am hosting on my server. There are no errors, however, the domain seems to be reading the htdocs folder instead of the DocumentRoot set for the VirtualHost. Here is the VirtualHost in question, of course with all domain/IP details removed.

Code:

<VirtualHost the.ip.address.here>
        ServerAdmin removed@email.address
        DocumentRoot /home/domain.com/public_html
        ServerName domain.com
        ServerAlias www.domain.com
        ErrorLog /home/domain.com/logs/error_log
        CustomLog /home/domain.com/logs/access_log common
        ScriptAlias /cgi-bin/ "/home/domain.com/cgi-bin"
</VirtualHost>

Here is my full httpd.conf file (not very long, so I am posting it here).

Code:

ServerRoot "/usr/local/apache"
Listen 80

LoadModule php5_module                modules/libphp5.so

<IfModule !mpm_netware_module>
        User daemon
        Group daemon
</IfModule>

ServerAdmin domain@removed.com
DocumentRoot "/usr/local/apache/htdocs"

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
</Directory>

<Directory "/usr/local/apache/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride  None
        Order allow,deny
        Allow from all
</Directory>

<IfModule dir_module>
        DirectoryIndex index.html
</IfModule>

<FilesMatch "^\.ht">
        Order allow,deny
        Deny from all
        Satisfy All
</FilesMatch>

ErrorLog logs/error_log
LogLevel warn

<IfModule log_config_module>
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i"" combined
        LogFormat "%h %l %u %t \"%r\" %>s %b" common

        <IfModule logio_module>
                LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
        </IfModule>

        CustomLog logs/access_log common
</IfModule>

<IfModule alias_module>
        ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
</IfModule>

<Directory "/usr/local/apache/cgi-bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
</Directory>

DefaultType text/plain

<IfModule mime_module>
        TypesConfig conf/mime.types
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
</IfModule>

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

<VirtualHost the.ip.address.here>
        ServerAdmin removed@email.address
        DocumentRoot /home/domain.com/public_html
        ServerName domain.com
        ServerAlias www.domain.com
        ErrorLog /home/domain.com/logs/error_log
        CustomLog /home/domain.com/logs/access_log common
        ScriptAlias /cgi-bin/ "/home/domain.com/cgi-bin"
</VirtualHost>

Please let me know if you see any errors that would prevent it from reading VirtualHost directives.

Thanks!

Splenden

leandean 01-11-2007 01:15 AM

Looks to me that it sees the default path: DocumentRoot "/usr/local/apache/htdocs" and doesn't have anything to tell it to look for a virtual host:

NameVirtualHost *:80

See:

http://httpd.apache.org/docs/2.0/vhosts/examples.html

Splenden 01-11-2007 09:47 AM

Does that apply for an IP-based virtual host? I am using unique IPs for all of my sites right now.

Thanks!

Splenden

poweredbydodge 01-12-2007 01:25 AM

Not to be back-asswards, but a single server shouldn't have more than one WAN IP address. I can understand multiple NIC's for varied LAN IP's, but one machine should only be accepting / broadcasting to one WAN IP, and therefore, I do not think Apache is setup to work on multiple IP's.

Obviously, the *:80 or *:443 or *:whatever-port will allow it to glom over and serve HTTP(S) to all IPs that come up for the machine. However, I am not so sure this was intended to be used for differentiating directories to be served by IP address.

None the less, I think your 'calling' of the VirtualHost directive is missing the port.

Quote:

<VirtualHost ip.address.here:port>
-----replace smiley face with : p ---
blah
blah
blah
</VirtualHost>
... might work. Your inital post showed that you placed the IP address in the call, but not the port. It could be something that simple.

Splenden 01-12-2007 11:18 PM

Dedicated servers and VPS'es can sometimes have more than one IP address - in fact, they usually do. It is not uncommon to see one machine with several IP addresses on it and one NIC.

I'll try the port thing and report back in the morning.

Thank you.

Splenden

Wim Sturkenboom 01-14-2007 12:50 AM

Quote:

Originally Posted by poweredbydodge
Not to be back-asswards, but a single server shouldn't have more than one WAN IP address. I can understand multiple NIC's for varied LAN IP's, but one machine should only be accepting / broadcasting to one WAN IP,

Just curious: Why?

I use IP-based virtual hosting (one nic, 4 addresses). I 'have to' as the 4 sites that I host (on an intranet) are all https sites; the only alternative is four dedicated servers.
I might be wrong, but I can't imagine that a hosting provider buys a new server for every client that wants https.

poweredbydodge 01-14-2007 01:20 AM

well... i hadn't thought about that.

although, i had thought that 'big servers' (the type that do hosting for various websites and such) just used domain name virtual hosting.

ie -- joeblow.com and myothersite.com would both redirect to the same IP, with virtual hosting taking care of sending requests for each to their respective directories.

as far as https goes, taking into account what i just said, certificates don't really care what IP they're coming from, they reference the domain. as long as the issuer and holder are from the domain calling https, then it shouldn't be an issue... i've run 3 domain names from my single IP address, all with virtual hosting, and all were able to run https.

Wim Sturkenboom 01-14-2007 11:43 AM

I wonder how you got that working; I could not get it working as I get the message in my browser that the certificate is not valid for the domain (or something like that; can't remember exact text anymore).

from http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html
Quote:

Why is it not possible to use Name-Based Virtual Hosting to identify different SSL virtual hosts?

Name-Based Virtual Hosting is a very popular method of identifying different virtual hosts. It allows you to use the same IP address and the same port number for many different sites. When people move on to SSL, it seems natural to assume that the same method can be used to have lots of different SSL virtual hosts on the same server.

It comes as rather a shock to learn that it is impossible.

The reason is that the SSL protocol is a separate layer which encapsulates the HTTP protocol. So the SSL session is a separate transaction, that takes place before the HTTP session has begun. The server receives an SSL request on IP address X and port Y (usually 443). Since the SSL request does not contain any Host: field, the server has no way to decide which SSL virtual host to use. Usually, it will just use the first one it finds, which matches the port and IP address specified.

Splenden 01-14-2007 11:56 AM

It was something in the config file. I decided to redo my config file and it worked fine. User error.

Thank you!

Splenden

leandean 01-14-2007 12:15 PM

You can only run one ssl server per port or address. To run more you must specify a separate port/address for each. ie: :443, 444, etc.

http://lists.freebsd.org/pipermail/f...il/000119.html

You can only resolve on SSL certificate to any given IP/port configuration.

Your apache conf file can be listening to 30 different IP address/port
configurations, and have 30 seperate SSL certificates for each.
<VirtualHost 123.456.789.1:443>
<VirtualHost 123.456.789.1:444>
<VirtualHost 123.456.789.1:445>
<VirtualHost 123.456.789.1:446>
or
<VirtualHost 123.456.789.1:443>
<VirtualHost 123.456.789.2:443>
<VirtualHost 123.456.789.3:443>
<VirtualHost 123.456.789.4:443>
are all acceptable with the appropriate certificate entries in each container.

You cannot however, have more than 1 SSL certificate for a single IP/Port
configuration.


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