我来写个详细的: Win32下具体实现Apache的用户验证(原创)
apache|原创
Win32下具体实现Apache的用户验证
相信大家采用的验证方法很多种,而在Win32环境下如何设置Apache用户验证的介绍很少,手册上介绍的也是Unix和linux环境下的配置,象我这样在win32下苦苦摸索Apache的人应该不少,我根据自己的经验介绍一下自己是如何在Win32环境下实现apache的用户验证功能的。
方法一:以单用户方式实现某目录只能由某个用户或几个用户访问。
假设Apache的web根目录为 d:/home,对应URL为 http://localhost/
如欲使d:/home/test目录只能由某用户访问,该目录对应URL为http://localhost/test,访问该URL时需要弹出验证对话框。
d:/users目录用来存放密码文件 user.passwd
1、制作用户密码文件
在命令行方式先用Apache自带的工具htpasswd.exe生成一个密码文件叫user.passwd,-c参数表示新建文件,无参数表示在该口令文件中以添加方式增加一个用户。
D:\apache\bin>htpasswd -bc d:/users/user.passwd user1 123456
这样,就生成了d:/users/user.passwd 口令文件,里面有一行文字 user1:$apr1$4S3.....$.su.8AIrDEYMX7jKv2RT9/
成功增加了一个user1的用户,如果想再添加其他用户,就采用追加方式添加用户:
D:\apache\bin>htpasswd -b d:/users/user.passwd user2 123456
D:\apache\bin>htpasswd -b d:/users/user.passwd user3 123456
好了,当添加完用户,就可以着手实现用户验证了。
2、制作访问验证文件 .htaccess
打开记事本,输入以下文字:
authtype basic
authname "www.home.net"
authuserfile d:/users/users.passwd
require user user1
然后另存为 .htaccess,保存路径为你想实现验证的目录:d:/home/test/下,注意保存类型选"所有文件",文件名为".htaccess",否则就不会生成 .htaccess 文件了。
到这里,指定某个用户验证的设置就完成了,在浏览器中输入验证目录所对应的地址 http://localhost/test/,会发现浏览器弹出一个对话框要求你输入用户名和口令,你就只能输入用户user1和密码12345才能进去,输入其他用户如user2,user3是没用的。
3、实现指定某几个用户对一个目录的验证
例如决定 http://localhost/test/ 能由user1和user3访问,user2不能访问,则编辑 d:/home/test/.htaccess 文件,把最后的一句:
require user user1
改为:
require user user1 user3
如此就实现了 http://localhost/test/ 只能由user1和user2访问
4、实现所有合法用户对一个目录的验证
例如决定 http://localhost/test/ 能由 d:/users/user.passwd 文件里的所有用户访问,则编辑 d:/home/test/.htaccess 文件,把最后的一句改为 :
require valid-user
就可以实现在 user.passwd 里用户都能访问http://localhost/test/了,只要输入的用户名和密码没有错误。
方法二:采用群组用户方式实现验证
要实现其实也很简单,在方法一中对 user.passwd 文件里的用户进行分组,建立用户组文件,再在 .htaccess 文件里指定 authgroupfile 就可以了。假设 user.passwd 中已经添加了很多用户 (user1,user2,user3,user4,...)
1、建立一个用户组文件 d:/users/user.group ,内容如下:
manager:user1 user3
game:user2 user4
download:user5 user6 user7
如此,user.group 文件里把 user1至user7这7个用户分为了3个组:manager,game,download 。
2、实现某组用户能访问 http://localhost/test/
编辑 d:/home/test/.htaccess 文件,内容如下:
authtype basic
authname "www.home.net"
authuserfile d:/users/users.passwd
authgroupfile d:/users/user.group
require group game
那么,http://localhost/test/就只能由 game组里的用户 user2,user4 才能访问了。
以上步骤,对于熟悉编程开发的同志来说,完全可以做个图形界面程序来完成,就省事多了。
至此,Apache在Win32环境下的简单验证就实现了。看来和 Linux下的设置方法差不多,我却走了不少弯路才摸索出来,惭愧惭愧啊。
实现Apache的验证方法还有数种途径,以上只是一方面而已。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Huawei is rolling out software version 5.0.0.100(C00M01) for the Watch GT 5 and the Watch GT 5 Prosmartwatchesglobally. These two smartwatches recently launched in Europe, with the standard model arriving as the company’s cheapest model. This Harmony

Katsuhiro Harada, the Tekken series director, once seriously tried to bring Colonel Sanders into the iconic fighting game. In an interview with TheGamer, Harada revealed that he pitched the idea to KFC Japan, hoping to add the fast-food legend as a g

Xiaomi will shortly launch the Mijia Graphene Oil Heater in China. The company recently ran a successful crowdfunding campaign for the smart home product, hosted on its Youpin platform. According to the page, the device has already started to ship to

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

The collaborative working mechanism between Apache or Nginx and PHP: Comparison of mod_php5, php-cgi and php-fpm is to use Apache or Nginx to build a web server and use PHP for backend...

DebianLinux is known for its stability and security and is widely used in server, development and desktop environments. While there is currently a lack of official instructions on direct compatibility with Debian and Hadoop, this article will guide you on how to deploy Hadoop on your Debian system. Debian system requirements: Before starting Hadoop configuration, please make sure that your Debian system meets the minimum operating requirements of Hadoop, which includes installing the necessary Java Runtime Environment (JRE) and Hadoop packages. Hadoop deployment steps: Download and unzip Hadoop: Download the Hadoop version you need from the official ApacheHadoop website and solve it

Apache errors can be diagnosed and resolved by viewing log files. 1) View the error.log file, 2) Use the grep command to filter errors in specific domain names, 3) Clean the log files regularly and optimize the configuration, 4) Use monitoring tools to monitor and alert in real time. Through these steps, Apache errors can be effectively diagnosed and resolved.
