htaccess-for-nginx icon indicating copy to clipboard operation
htaccess-for-nginx copied to clipboard

Error processing url with pound signs

Open myrandor opened this issue 3 years ago • 2 comments

I started using PHPNuGet to make a local chocolatey server. When I try to install a package or search, Chocolatey send the request correctly, but nginx is not able to process it and gives me errors in htaccess.lua

Any hint how to fix it?

Here's the error from nginx

2022/11/02 18:50:03 [error] 24#24: *1947 lua entry thread aborted: runtime error: /etc/nginx/lua/htaccess.lua:797: invalid capture index
stack traceback:
coroutine 0:
        [C]: in function 'gsub'
        /etc/nginx/lua/htaccess.lua:797: in function 'replace_server_vars'
        /etc/nginx/lua/htaccess.lua:1055: in main chunk, client: 0.0.0.0, server: _, request: "GET /nuget/api/v2/Packages()?$filter=(tolo
wer(Id)%20eq%20'chocolatey')%20and%20IsLatestVersion HTTP/1.1", host: "www.www.www"

2022/11/02 19:25:01 [error] 23#23: *12 lua entry thread aborted: runtime error: /etc/nginx/lua/htaccess.lua:797: invalid capture index
stack traceback:
coroutine 0:
        [C]: in function 'gsub'
        /etc/nginx/lua/htaccess.lua:797: in function 'replace_server_vars'
        /etc/nginx/lua/htaccess.lua:1061: in main chunk, client: 0.0.0.0, server: _, request: "GET /nuget/api/v2/Search()?$orderby=Id,Ver
sion%20desc&$skip=0&$top=30&searchTerm='choco'&targetFramework=''&includePrerelease=false HTTP/1.1", host: "www.www.www"

And here's the htaccess lines for these paths

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  !index\.php          [NC]
RewriteCond %{REQUEST_URI}  ^/nuget/api/v2/Packages\(\)  [NC] 
RewriteRule  .* /nuget/api/v2/index.php?action=packages   [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  !index\.php          [NC]
RewriteCond %{REQUEST_URI}  ^/nuget/api/v2/Search\(\)  [NC] 
RewriteRule  .* /nuget/api/v2/index.php?action=search   [QSA]

myrandor avatar Nov 02 '22 23:11 myrandor

@myrandor the referenced PR will make the two sample URLs in your log

/nuget/api/v2/Packages()?$filter=(tolower(Id)%20eq%20'chocolatey')%20and%20IsLatestVersion

/nuget/api/v2/Search()?$orderby=Id,Version%20desc&$skip=0&$top=30&searchTerm='choco'&targetFramework=''&includePrerelease=false

redirect as expected.

Note that pound signs are handled by the browser so are never passed to the server anyway.

rkaiser0324 avatar Dec 10 '22 19:12 rkaiser0324

Awesome @rkaiser0324, thanks for taking the time. @myrandor please test the updated script and give some feedback if things are working on your end.

e404 avatar Dec 11 '22 07:12 e404