apache2 UserDir 拒绝除我之外的所有人

apache2 UserDir 拒绝除我之外的所有人

我已经为 PHP 网站开发/个人托管设置了一个 Debain 6 VPS,并且有一个简单的问题:

我想要将生产代码托管在:/var/www/site.com,并将开发代码托管在 /home/username/public_html/site

我已经设置了 userdir.conf (我认为是默认设置):

<IfModule mod_userdir.c>
    UserDir public_html
    UserDir disabled root

    <Directory /home/*/public_html>
            AllowOverride All
            Options MultiViews Indexes SymLinksIfOwnerMatch
            <Limit GET POST OPTIONS>
                    Order allow,deny
                    Allow from all
            </Limit>
            <LimitExcept GET POST OPTIONS>
                    Order deny,allow
                    Deny from all
            </LimitExcept>
    </Directory>
</IfModule>

我可以分别通过 www.site.com 和 www.site.com/~username/site 访问这两个代码库

我的问题是:限制 www.site.com/~username/site(我的项目处于开发状态)对外界访问的最佳方法是什么?(.htaccess、虚拟主机设置、其他)

答案1

如果你从固定 IP 地址连接到 VPS,那么更改 IPAllow from all地址Allow from IP.AD.RE.SS既快捷又简单。如果没有,那么你可以设置基本身份验证使用 .htaccess 文件。输入类似

AuthType Basic
AuthName Private
Authuserfile /path/to/.htpasswd
Require valid-user

在 public_html/.htaccess 文件中。

初始化.htpasswd 文件

htpasswd -c /path/to/.htpasswd Purplefish32
New password: mypassword
Re-type new password: mypassword
Adding password for user Purplefish32

然后确保你的主要 Apache 配置有合适的允许覆盖指令例如AllowOverride AuthConfig。如果需要,请重新启动 apache,现在应该要求您提供密码才能访问开发文件的内容。

相关内容