htaccess-for-nginx
htaccess-for-nginx copied to clipboard
Error processing url with pound signs
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 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.
Awesome @rkaiser0324, thanks for taking the time. @myrandor please test the updated script and give some feedback if things are working on your end.