2

I'm running a local server on windows and I want to provide lan access to a specific part of it whenever a variable is defined. It works fine, except the main config is served instead of the virtual host.

I've specifically made the virtual host point to a forbidden directory with the wrong DirectoryIndex to make sure it actually works, but the page is always served correctly, no matter what I do. Here's the virtual host:

<VirtualHost ${LANIP}:${PORT}>
    DocumentRoot ${SRVROOT}/htdocs/phpinfo
    ServerName ${LANIP}:${PORT}
    DirectoryIndex index.pl
</VirtualHost>

and here's the complete httpd.conf, stripped of comments.

When I use httpd -DLANACCESS -S, this is the output:

c:\fauna\apache\bin>httpd -DLANACCESS -S                                
VirtualHost configuration:                                               
192.168.1.6:80         192.168.1.6 (C:/fauna/apache/conf/httpd.conf:464)
ServerRoot: "c:/fauna/apache"                                           
Main DocumentRoot: "C:/fauna/apache/htdocs"                             
Main ErrorLog: "c:/fauna/apache/logs/error.log"                         
Mutex rewrite-map: using_defaults                                        
Mutex lua-ivm-shm: using_defaults                                        
Mutex default: dir="C:/fauna/apache/logs/" mechanism=default            
PidFile: "c:/fauna/apache/logs/httpd.pid"                               
Define: LANACCESS                                                        
Define: DUMP_VHOSTS                                                      
Define: DUMP_RUN_CFG                                                     
Define: FAUNAROOT=/fauna                                               
Define: WIN_FAUNAROOT=C:\fauna                                         
Define: SRVROOT=/fauna/apache                                           
Define: WIN_SRVROOT=C:\fauna\apache                                     
Define: PERLPATH=C:\fauna\perl                                          
Define: WIN_PERLPATH=C:\fauna\perl                                      
Define: LANIP=192.168.1.6                                                
Define: PORT=80         

This, I think, indicates Apache is correctly identifying that there is a VirtualHost directive, but is ignoring everything within it or somehow it doesn't match. No matter what, if I path to localhost from the server or 192.168.1.6 from another machine on the lan, it serves the same page. It respects permissions, but from the lan it should break and give a 404 with this test config, not serve the main site.

I even tried overriding the default vhost:

<VirtualHost _default_>
    DocumentRoot ${SRVROOT}/htdocs/nothing
    ServerName localhost:80
</VirtualHost>

which gives this output from Apache:

c:\fauna\apache\bin>httpd -DLANACCESS -S
AH00112: Warning: DocumentRoot [c:/fauna/apache/htdocs/nothing] does not exist
VirtualHost configuration:
192.168.1.6:80         192.168.1.6 (C:/fauna/apache/conf/httpd.conf:464)
*:80                   localhost (C:/fauna/apache/conf/httpd.conf:474)
ServerRoot: "c:/fauna/apache"
Main DocumentRoot: "C:/fauna/apache/htdocs"
Main ErrorLog: "c:/fauna/apache/logs/error.log"
Mutex rewrite-map: using_defaults
Mutex lua-ivm-shm: using_defaults
Mutex default: dir="C:/fauna/apache/logs/" mechanism=default
PidFile: "c:/fauna/apache/logs/httpd.pid"
Define: LANACCESS
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: FAUNAROOT=/fauna
Define: WIN_FAUNAROOT=C:\fauna
Define: SRVROOT=/fauna/apache
Define: WIN_SRVROOT=C:\fauna\apache
Define: PERLPATH=C:\fauna\perl
Define: WIN_PERLPATH=C:\fauna\perl
Define: LANIP=192.168.1.6
Define: PORT=80

So, apparently, it does parse the VirtualHost tags. However, this has the exact same effect and both virtualhosts are completely ignored, as if they don't match.

edit - I have confirmed through mod_info that the VirtualHost does indeed match, but of course DocumentRoot and DirectoryIndex are completely ignored for some reason.

0

tl;dr: Unless I'm mistaken, setting up aliases on the main server requires setting them up separately in virtualhosts, otherwise the main site gets served due to aliases, especially if you've aliased / like I had. Not 100% sure of this but it makes sense based on what I got.

I seem to have solved it using this definition for the virtualhost:

<IfDefine LANACCESS>
    <VirtualHost ${LANIP}:${PORT}>
        Alias "/" "${SRVROOT}/htdocs/phpinfo/"
        # DocumentRoot ${SRVROOT}/htdocs/phpinfo
        <Directory "${SRVROOT}/htdocs/phpinfo">
            AllowOverride None
            # Options -ExecCGI
            Require ip 192.168.1
            # DirectoryIndex phpinfo.php
        </Directory>
        Redirect 404 /info
        Redirect 404 /status
        ServerName ${LANIP}:${PORT}
    </VirtualHost>
</IfDefine>

Previously, access would register as going through the virtual host, but would serve the main page. By aliasing / with the intended DocumentRoot, it serves the intended page properly. Directory is necessary to set proper permissions, otherwise it seems to inherit from the previous Directory definition or go with defaults or something. Thus, if your previous Directory definition requires amending, do so.

DocumentRoot apparently has no effect. I don't know why, but removing it from the main config seems to have no effect there either. Perhaps the way I set things up overrides it.

If you're using Location for things like mod_info or otherwise, use Redirect 404 to cancel those locations or Require to forbid access, otherwise they operate as normal, regardless of any Alias directives you've set up.

Unless you set up Aliases for the rest of the server locations, previous ones appear to be inactive when overriding / or for some other reason I can't figure out.

0

You are likely falling victim to windows filesystem virtualization, where files edited by non-Administrator appear changed for you but not for httpd running as a service.

Edit your configuration with the true Administrator account.

1
  • I am not running apache as a service since this setup is still in the development phase. I manually start and stop apache from the command line. The -S switch pretty much indicates this is not a problem of apache not seeing the changed config file and every time I change something I know will have an effect, it behaves as expected. Also, my user is an administrator. I know what you mean by "true" administrator, but as I've indicated, this doesn't seem to be the issue at all. – mechalynx Dec 26 '15 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.