-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
I'm getting an error using htaccess.lua
with openresty/1.21.4.1
under the following circumstances:
-
I'm using the latest
htaccess.lua
from this repository. I've placed it in/usr/local/openresty/nginx/scripts
. -
I have a directory,
/usr/local/openresty/nginx/html/protected
, which I'm trying to protect using.htaccess
. -
The
.htaccess
file (/usr/local/openresty/nginx/html/protected/.htaccess
) contents are:
AuthType Basic
AuthName "Restricted Content"
AuthUserFile .htpasswd
Require valid-user
- The nginx configuration (relevant portions) are:
http {
...
lua_shared_dict htaccess 4m;
...
}
server {
...
rewrite_by_lua_file /usr/local/openresty/nginx/scripts/htaccess.lua;
...
location / {
root html;
index index.html index.htm;
}
...
}
When the rewrite_by_lua_file
line is commented out, I can access content in /protected
, as expected. When not commented out, access to /protected/index.html
leads to a Lua runtime error:
2023/05/30 09:15:43 [error] 18532#18532: *17 lua entry thread aborted: runtime error: /usr/local/openresty/nginx/scripts/htaccess.lua:119: attempt to concatenate global 'doc_root' (a nil value)
stack traceback:
coroutine 0:
/usr/local/openresty/nginx/scripts/htaccess.lua: in function 'ensure_doc_root'
/usr/local/openresty/nginx/scripts/htaccess.lua:145: in function 'get_file_contents'
/usr/local/openresty/nginx/scripts/htaccess.lua:507: in function 'parse_htaccess_directive'
/usr/local/openresty/nginx/scripts/htaccess.lua:1012: in main chunk, client: 146.90.194.232, server: foo.bar.com, request: "GET /protected/index.html HTTP/2.0", host: "foo.bar.com"
Any idea what could be the cause of the problem? It seems like in
htaccess-for-nginx/htaccess.lua
Lines 114 to 118 in b81c1f1
local ensure_doc_root = function(filepath) | |
if not in_doc_root(filepath) then | |
fail(C_SECURITY_VIOLATION_ERROR..': Trying to read file outside of server root directory ("'..doc_root..'"): "'..filepath..'"') | |
end | |
end |
there's a reference to
doc_root
, which is not defined globally and is local to in_doc_root
.Metadata
Metadata
Assignees
Labels
No labels