e404 / htaccess-for-nginx

.htaccess for nginx enables the nginx high performance webserver to deal with .htaccess files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash for unknown reason

ethernidee opened this issue · comments

The following simple .htaccess file produces 500 error:

## No directory listings
Options -Indexes

<IfModule autoindex>
  IndexIgnore *
</IfModule>

RewriteEngine On
RewriteBase /

## Begin - Rewrite rules to block out some common exploits ##
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
## End - Rewrite rules to block out some common exploits ##

# Remove trailing backslash from URIs
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\/$ $1 [R=301,L]

## Begin - Core SEF Section ##
#RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
## End - Core SEF Section ##

Error:

*211 lua entry thread aborted: runtime error: /etc/nginx/lua/htaccess.lua:796: bad argument #2 to 'gsub' (string/function/table expected)
stack traceback:
coroutine 0:
  [C]: in function 'gsub'
  /etc/nginx/lua/htaccess.lua:796: in function 'replace_server_vars'
  /etc/nginx/lua/htaccess.lua:1060: in function </etc/nginx/lua/htaccess.lua:1>, client: 0.0.0.0, server: test.com, request: "POST /api/receive-signals HTTP/1.1", host: "test.com"
2023/01/31 04:30:31 [error] 766145#766145: *212 lua entry thread aborted: runtime error: /etc/nginx/lua/htaccess.lua:796: bad argument #2 to 'gsub' (string/function/table expected)
stack traceback:
coroutine 0:
  [C]: in function 'gsub'
  /etc/nginx/lua/htaccess.lua:796: in function 'replace_server_vars'
  /etc/nginx/lua/htaccess.lua:1060: in function </etc/nginx/lua/htaccess.lua:1>, client: 0.0.0.0, server: test.com, request: "GET /admin/panel HTTP/2.0", host: "test.com", referrer: "https://test.com/admin/login"
2023/01/31 04:30:33 [error] 766145#766145: *212 lua entry thread aborted: runtime error: /etc/nginx/lua/htaccess.lua:796: bad argument #2 to 'gsub' (string/function/table expected)
stack traceback:
coroutine 0:
  [C]: in function 'gsub'
  /etc/nginx/lua/htaccess.lua:796: in function 'replace_server_vars'
  /etc/nginx/lua/htaccess.lua:1060: in function </etc/nginx/lua/htaccess.lua:1>, client: 0.0.0.0, server: test.com, request: "GET /favicon.ico HTTP/2.0", host: "test.com", referrer: "https://test.com/admin/panel"

I would also look at the following code:

elseif svar == 'script_filename' then -- %{SCRIPT_FILENAME}
  replace = ngx.var['fastcgi_script_name']
  
  if not replace or replace == '' then
    replace = ngx.var['request_filename']
  else
    replace = (ngx.var['document_root']..'/'..script_filename):gsub('/+', '/')
  end
  replace = script_filename

Seems like the last line replace = script_filename is odd or condition block should be removed.