这是我目前所拥有的:
<VirtualHost *:80>
DocumentRoot "/PathToTheFilesThat/theserver/gives/access/to"
ServerName docs.mysite.com
ProxyPass / http://localhost:8808/
ProxyPassReverse / http://localhost:8808
</VirtualHost>
基本上,我只是想让 YARD 文档服务器对我工作的公司公开(但不是向全世界公开),因此需要基本身份验证。
以上内容目前允许从任何远程机器访问服务器...只需要授权。=D
更新:
<VirtualHost *:80>
DocumentRoot "/Users/me/projects/myProject/doc"
ServerName docs.mysite.com
ProxyPass / http://localhost:8808/
ProxyPassReverse / http://localhost:8808
AuthUserFile /private/etc/apache2/conf/.htpasswd
AuthName "Documentation Server, Please Log In"
AuthType Basic
Require User me
</VirtualHost>
当我导航到 docs.mysite.com (在控制台中)时出现此错误
[Tue Feb 21 11:33:04 2012] [error] (61)Connection refused: proxy: HTTP: attempt to connect to [fe80::1]:8808 (localhost) failed
[Tue Feb 21 11:33:04 2012] [error] ap_proxy_connect_backend disabling worker for (localhost)
[Tue Feb 21 11:35:16 2012] [notice] caught SIGTERM, shutting down
答案1
为了在您的 Web 服务器的入口点启用用户身份验证,您必须将以下行添加到 VirtualHost 配置行中。
<VirtualHost>
..
..
..
..
..
AuthUserFile /usr/local/apache2/conf/.htpasswd
AuthName "yoursite.com, Please Log In."
AuthType Basic
Require User userallowedtoenter
</VirtualHost>
通过添加这些行,每次您打开网站时,都会弹出一个身份验证窗口,要求输入用户/密码。
答案2
感谢@GersonO 让我走上正轨!但至少在 2022 年,这不再有效,但你需要一个
<Directory /var/www/example.de/htdocs/>
AuthUserFile /etc/apache2/htpasswd
AuthName "Stage Server"
AuthType Basic
Require valid-user
</Director>