1

I have a Apache 2.2 web server running multiple HTTP and HTTPS virtual hosts, these work fine. Now I need to add an FTP vhost (there was one before!), and while httpd -S displays all vhosts, only the default one gets to authorize requests. The mod_ftp manual says there is an FTP option to mod_ftp to redirect to proper vhost if the USER command provides a name, still logs arrive to first vhost's error log stating "no user found user@secondhost.com". Respective config lines are here:

LoadModule ftp_module modules/mod_ftp.so
Listen 21 ftp
FTPOptions StripHostName VirtualHostByUser 
# this should allow selecting vhosts by hostname part in user@hostname
NameVirtualHost *:21

#first vhost
<VirtualHost *:21>
    FTP On
    ServerAdmin xxx@firsthost.com
    DocumentRoot "d:/webroot/firsthost"
    ServerName www.firsthost.com
    ServerAlias firsthost.com
    ErrorLog "d:/webroot/logs/firsthost-ftp-error.log"
    CustomLog "d:/webroot/logs/firsthost-ftp-access.log" common
    SSLEngine off

    <Directory />
        AllowOverride None
        Options Indexes -FollowSymLinks
        Order deny,allow
        Allow from all
        ForceType text/plain
        AuthType basic
        AuthBasicProvider file
        AuthUserFile "C:/server/apache/conf/extra/vhosts/firsthost-htpasswd.users"
        AuthName "firsthost.com FTP"
        Require valid-user
    </Directory>
</VirtualHost>

#second vhost - never gets to be addressed
<VirtualHost *:21> 
    FTP On
    ServerAdmin xxx@secondhost.com
    DocumentRoot "d:/webroot/secondhost.com"
    ServerName www.secondhost.com
    ServerAlias secondhost.com
    SSLEngine off
    <Directory />
        AllowOverride None
        Options Indexes -FollowSymLinks
        Order deny,allow
        Allow from all
        ForceType text/plain
        AuthType basic
        AuthBasicProvider file
        AuthUserFile "C:/server/apache/conf/extra/vhosts/secondhost-htpasswd.users"
        AuthName "secondhost.com FTP"
        # doesn't work anyway, we don't have hostname at AuthName state
        Require valid-user
    </Directory>
    ErrorLog "d:/webroot/logs/secondhost-error.log"
    CustomLog "d:/webroot/logs/secondhost-access.log" common
</VirtualHost>

I use totalcmd to test, and it clearly states "firsthost.com FTP" gets advertised, and nothing can be made to switch to secondhost.com. As I understand the problem, while one host should really respond to connection, as FTP does not allow selecting host by name prior to authenticating, Apache should then change vhost definition used when receiving USER user@secondhost.com by FTP and review its vhosts to grab the correct password file and correct home directory. It doesn't. Any usable solutions, except for running FTP sites on different ports (where Apache would clearly differ between those hosts by connection request)?

PS: OS is Windows Server 2008R2, so building either Apache or mod_ftp from sources is out of reach. This can be a bug in particular executable set of Apache+mod_ftp. Apache responds with:

Server version: Apache/2.2.24 (Win32)
Server built:   Mar  1 2013 22:27:56

mod_ftp responds with: mod_ftp 0.9.6

0

I never knew that Apache would work as an FTP server, you learn something new every day :)

In general: when using VirtualHost entries in Apache many options from the main server get suppressed and instead need to be set in the <VirtualHost> ... </VirtualHost> block.

I think that may be the case for FTPOptions VirtualHostByUser as well.

Try:

<VirtualHost *:21>
    FTP On
    ServerName www.firsthost.com
    ServerAlias firsthost.com
    FTPOptions StripHostName VirtualHostByUser 
    ...
</VirtualHost>

<VirtualHost *:21> 
    FTP On
    ServerName www.secondhost.com
    ServerAlias secondhost.com
    FTPOptions StripHostName VirtualHostByUser 
    ...
</VirtualHost>
1
  • Hmm, something to check indeed. Some directives indeed don't inherit from base configuration. Will come back at you with results in a day or two. – Vesper Sep 6 '18 at 12:58

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.