How to set up htaccess and htpasswd in my private server?

£可爱£侵袭症+ 提交于 2019-12-24 07:38:11

问题


At the moment I'm trying set up authentication on my test server.

The following is the list of files in the folder I'm trying to set up authentication for.

sftp://it@192.168.0.157/var/www/secret/.htpasswd
sftp://it@192.168.0.157/var/www/secret/.htaccess
sftp://it@192.168.0.157/var/www/secret/index.html

Here's what .htaccess contains:

AuthName "Restricted Area"
AuthType Basic 
AuthUserFile /secret/.htpasswd 
AuthGroupFile /dev/null 
<Files test.html>
require valid-user
</Files>

I'm not getting the login pop up. It simply shows the index.html when I go to 192.168.0.157/secret

What am I not doing correctly?

Oh btw, please ignore the fact that I haven't placed the htpasswd file in a more secure location. I just want to get this to work once and be able to demonstrate it.


回答1:


You have stated URLs to a FTP server, not to the Apache web server.
When trying to access webserver, url will be: http://192.168.0.157/secret/index.html

In .htaccess you have stated that access should be controller only for test.html

Use this .htaccess for controlling access to all files:

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /secret/.htpasswd
Require valid-user


来源:https://stackoverflow.com/questions/11905751/how-to-set-up-htaccess-and-htpasswd-in-my-private-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!