PHP经验分享

apache 文件路径验证授权即添加用户名密码设置

2019-02-18  本文已影响0人  大崔同学的简书

apache 给文件夹添加访问权限

参考链接如下:
https://httpd.apache.org/docs/2.4/howto/auth.html

上述页面上是关于apache Authentication and Authorization (验证和授权) 的相关配置。

文中说,可以在 .htaccess 和 apache.conf 任意两文件中写下自己的配置。不过配置.htaccess文件需要在apache.conf配置文件中写上这句命令 AllowOverride AuthConfig

经过总结,最后我的配置如下:


# except summaryPage_interval and xcoinIsRunning
# SetEnvIf Request_URI (summaryPage_interval|xcoinIsRunning) noauth
SetEnvIf Request_URI xcoinIsRunning noauth

<Location "/api/bitmex/" >

        AllowOverride None

        AuthType Basic
        AuthName "bitmex"
        AuthBasicProvider file
        AuthUserFile "/usr/local/apache/passwd/passwords"
        Require user admin

        Order Deny,Allow
        Satisfy any
        Deny from all
        Allow from env=noauth

</Location>

最终,实现了对路径的验证和授权(即需要输入用户名和密码),如果把上述代码放在<Directory> 中,只能对目录起作用,对路径和文件是没用的。

设置用户名和密码的方法参考链接中是有的。贴原文如下:

To create the file, type:

htpasswd -c /usr/local/apache/passwd/passwords rbowen 

htpasswd will ask you for the password, and then ask you to type it again to confirm it:

# htpasswd -c /usr/local/apache/passwd/passwords rbowen
New password: mypassword
Re-type new password: mypassword
Adding password for user rbowen
...

上一篇下一篇

猜你喜欢

热点阅读