gpt4 book ai didi

linux - httpd.conf 代码无法正常工作——建议?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:06:03 25 4
gpt4 key购买 nike

与我之前的问题相关:.htaccess check for cookie first, then valid-user

大家好,非常感谢这里专家的帮助。我的 httpd.conf 应该需要使用 mod_auth_mysql 或 cookie 的用户登录 - 但现在它只检查用户登录。上一个问题的代码现在位于我的 httpd.conf 中。

什么在起作用:

目前,用户的所有/var/www/downloads 和子目录 (/var/www/downloads/~username~) 都需要使用 mod_auth_mysql 的用户名和密码。这行得通。

什么不起作用:

问题是:我的设置应该要求或者使用mod_auth_mysql(有效)登录,或者cookie(无效)。如果 cookie 存在,那么当用户访问/var/www/downloads/时,它应该会自动显示目录的内容。但它没有,它仍然要求输入用户名/密码。

我正在使用 SetEnvIf,但它可能被错误地用于“满足所有”。我可能在 httpd.conf 和/sites-enabled/000-default 之间有冲突。我对这里的大部分内容都没有经验,因此非常感谢任何帮助!

HTTPD.conf:

RewriteEngine on
RewriteLogLevel 9
RewriteLog /var/www/logs/rewrite.log

#Block IPs
<Directory /var/www>
RewriteEngine On

#only use my server for apache
RewriteCond %{HTTP_HOST} !^2.2.2.2$ [NC]
RewriteRule ^(.*)$ http://www.google.co.uk/$1 [L,R=301]

RewriteCond %{REMOTE_ADDR} 0.0.0.0 [NC,OR]
RewriteCond %{REMOTE_ADDR} 1.1.1.1 [NC]
RewriteRule ^(.*)$ http://www.google.com [R]
</Directory>

# DOWNLOADS TOP DIRECTORY
<Directory /var/www/downloads>
#Options Indexes
#AllowOverride All
#Order deny,allow
#Deny from all
#Allow from All

AuthName "Please don't hack the server, thanks"
AuthBasicAuthoritative Off
AuthUserFile /dev/null
AuthMySQL On
AuthType Basic
Auth_MYSQL on
Auth_MySQL_Host localhost
Auth_MySQL_User user
Auth_MySQL_Password password
AuthMySQL_DB db
AuthMySQL_Password_Table users
Auth_MySQL_Username_Field username
Auth_MySQL_Password_Field password
Auth_MySQL_Empty_Passwords Off
Auth_MySQL_Encryption_Types Plaintext
Auth_MySQL_Authoritative On
require user luke

</Directory>

# EXAMPLE USERS DIRECTORY
# MIKE
<Directory /var/www/downloads/mike>
SetEnvIf Cookie (.*)cookiename(.*) norequire_auth=yes
Order Deny,Allow
deny from all
Satisfy Any

#MYSQL AUTH
AuthName "Please login"
AuthBasicAuthoritative Off
AuthUserFile /dev/null
AuthMySQL On
AuthType Basic
Auth_MYSQL on
Auth_MySQL_Host localhost
Auth_MySQL_User user
Auth_MySQL_Password password
AuthMySQL_DB db
AuthMySQL_Password_Table users
Auth_MySQL_Username_Field username
Auth_MySQL_Password_Field password
Auth_MySQL_Empty_Passwords Off
Auth_MySQL_Encryption_Types Plaintext
Auth_MySQL_Authoritative On
require user mike

#COOKIE AUTH
Allow from env=norequire_auth
</Directory>

如果有帮助,sites-enabled/000-default: 可能会导致冲突? http://jsfiddle.net/Xcece/

我没有使用 .htaccess 文件。我已经更改了一大堆指令,但已经迷路了。

我终其一生都无法弄清楚为什么它不起作用 - 我不太了解可能存在的冲突,所以在正确的方向和解释上指出一点,这样我就可以在未来避免这种情况伟大的。谢谢。

最佳答案

终于!经过一周的寻找...

问题出在设置 cookie 上。将文件放在不同的目录中意味着 httpd.conf 没有正确读取 cookie - 实际上是正确的

我必须将 cookie 的第四个参数设置为“/downloads/mike”,从而允许 httpd.conf 文件正确读取它。

session_start();
setcookie("cookiename","cookiename",time() + 3600, '/downloads/mike');

请记住在使用 time()-x 销毁 cookie 时使用第四个参数 /downloads/mike 销毁它。

关于linux - httpd.conf 代码无法正常工作——建议?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13396655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com