我为运行apache2的ubuntu网络服务器设置了http-auth。我已通过以下步骤完成此操作(请注意,实例已运行apache2,并且路由53 dns地址的A记录):
mkdir -p /etc/httpd/conf.d
apt-get install -y apache2-utils
htpasswd -b -c /etc/apache2/.htpasswd demo $PASSWORD
然后我创建了文件/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
DocumentRoot /var/www/blah/
ServerName some-test.blah.info
ServerAdmin some-random-admin
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/blah/">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
</VirtualHost>
最后,我通过重新启动apache来应用此更改。
此后,通过IP地址提供凭证提示(用于用户名和密码),但不提供通过route53设置的DNS地址。
我认为问题是路由53问题,因为当你直接进行IP地址时它正常工作。
答案 0 :(得分:0)
解决方案是编辑/etc/apache2/apache2.conf
并找到目录部分(它应该是第153到174行)并添加auth要求。所以基本上找到所有目录并在每个目录中添加这四行:
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
例如,这就是它最初的样子:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
这就是需要改变的地方:
<Directory />
Options FollowSymLinks
AllowOverride None
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
<Directory /usr/share>
AllowOverride None
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
<Directory "/var/www/blah/">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>