.htpasswd没有.htaccess

don*_*ote 4 .htpasswd

我想通过.htpasswd保护一个Web文件夹.但是,由于.htaccess文件受版本控制,我宁愿不要乱用它.

相反,我想在
/ etc/apache2/sites-enabled/mysite
/etc/apache2/.htpasswd中进行配置

知道我需要在"mysite"apache配置文件中添加什么内容吗?

到目前为止它是这样的,

<VirtualHost (ip address):80>
  ServerName   my.domain
  DocumentRoot /var/sites/sitename
  ServerAdmin  ...
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

don*_*ote 5

Heureka,我自己想出来......或者我认为是解决方案.

<VirtualHost (ip address):80>
  ServerName   my.domain
  DocumentRoot /var/sites/sitename/
  ServerAdmin  ...
  <Directory /var/sites/sitename/>
    AuthUserFile  /etc/apache2/.htpasswd
    AuthGroupFile /dev/null
    AuthName  "What is the pw"
    AuthType Basic
    require user (username)
  </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

.htpasswd可以通过命令行以通常的方式创建,

# htpasswd /etc/apache2/.htpasswd (username)
Run Code Online (Sandbox Code Playgroud)

编辑:以下评论中的anthony强烈建议您使用https/SSL,以防止密码以未加密的方式发送.