我有一个运行多个 HTTP 和 HTTPS 虚拟主机的 Apache 2.2 Web 服务器,它们运行良好。现在我需要添加一个 FTP 虚拟主机(之前有一个!),虽然httpd -S
显示所有虚拟主机,但只有默认虚拟主机可以授权请求。mod_ftp 手册说如果 USER 命令提供了名称,mod_ftp 有一个 FTP 选项可以重定向到正确的虚拟主机,但日志仍然到达第一个虚拟主机的错误日志,指出“未找到用户[电子邮件保护]“。相应的配置行如下:
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 [email protected]
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 [email protected]
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>
我使用 totalcmd 进行测试,它清楚地表明“firsthost.com FTP”已得到宣传,并且无法切换到 secondhost.com。据我了解,虽然一台主机应该真正响应连接,因为 FTP 不允许在身份验证之前按名称选择主机,但 Apache 应该更改FTP 接收时使用的 vhost 定义并检查其 vhost 以获取正确的密码文件和正确的主目录。但事实并非如此。除了在不同的端口上运行 FTP 站点(Apache 会根据连接请求在这些主机之间明显区分)之外,还有其他可用的解决方案吗?USER [email protected]
PS:操作系统是 Windows Server 2008R2,因此无法从源代码构建 Apache 或 mod_ftp。这可能是 Apache+mod_ftp 特定可执行集的一个错误。Apache 响应:
Server version: Apache/2.2.24 (Win32)
Server built: Mar 1 2013 22:27:56
mod_ftp 响应:mod_ftp 0.9.6
答案1
我从来不知道 Apache 可以用作 FTP 服务器,每天都会学到新东西 :)
一般来说:在 Apache 中使用 VirtualHost 条目时,主服务器的许多选项会被抑制,而需要在<VirtualHost> ... </VirtualHost>
块中进行设置。
我思考这可能是FTPOptions VirtualHostByUser
也一样。
尝试:
<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>