引言
因为我的电脑通过ApacheHttpd搭建了一个Php的服务器,作为日常使用的NAS以及文件服务,还有一些靶场,,乌云镜像等等,但是内网中确实有一些大牛,仅允许本地访问也不太现实,因为偶尔使用Termux来做,所以换一种思路,emm,加个密码吧。
截图



实践
- 切换到apache的bin目录中,在控制台中输入htpasswd.exe -c "d:/software/apache/conf/.awspwd" admin
也就是说,通过htpasswd 中的 -c 来创建一个密码文件,后面接着密码文件路径以及文件名,最后是用户名 - 然后输入两次密码,这样就生成了密码文件
D:\Software\Apache\bin>htpasswd.exe -c "d:/software/apache/conf/pwd.cfg" admin
New password: ***
Re-type new password: ***
Adding password for user admin
```
3. 在www目录,也就是网站的根目录创建.htaccess文件
```bash
authname "私人站点,非授权禁止访问"
authtype basic
authuserfile conf/.awspwd
require valid-user
```
4. 这样就可以了
# 提示
authuserfile可以使用绝对路径,默认是apache根目录
# vhost
我的印象里应该是没有修改vhost,但是有的人说需要改,我也不记得默认是什么了,所以附上我的vhost
DocumentRoot "D:/Software/Apache/WWW"
FcgidInitialEnv PHPRC "D:/Software/php/php-7.4.3nts"
AddHandler fcgid-script .php
FcgidWrapper "D:/Software/php/php-7.4.3nts/php-cgi.exe" .php
<Directory "D:/Software/Apache/WWW">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
DirectoryIndex index.php index.html
ErrorDocument 400 /error/400.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
ErrorDocument 501 /error/501.html
ErrorDocument 502 /error/502.html
ErrorDocument 503 /error/503.html
ErrorDocument 504 /error/504.html
ErrorDocument 505 /error/505.html
ErrorDocument 506 /error/506.html
ErrorDocument 507 /error/507.html
ErrorDocument 510 /error/510.html
DocumentRoot "D:/Software/Apache/WWW/VHOST"
FcgidInitialEnv PHPRC "D:/Software/php/php-7.4.3nts"
AddHandler fcgid-script .php
FcgidWrapper "D:/Software/php/php-7.4.3nts/php-cgi.exe" .php
<Directory "D:/Software/Apache/WWW/VHOST">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
DirectoryIndex index.php index.html
ErrorDocument 400 /error/400.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
ErrorDocument 501 /error/501.html
ErrorDocument 502 /error/502.html
ErrorDocument 503 /error/503.html
ErrorDocument 504 /error/504.html
ErrorDocument 505 /error/505.html
ErrorDocument 506 /error/506.html
ErrorDocument 507 /error/507.html
ErrorDocument 510 /error/510.html
```
nginx配置
如果需要nginx的配置,可参阅文章:


评论 0
还没有评论,来说点什么吧。