Hey and thanks tokers :) that is perfectly ok no need to apologize your English is fantastic and understandable for me :)
I have hit a problem with try_files with this. Here is the full code :
Here is my code :
##HTTP BLOCK
map $request_body $cache_request_body {
default $request_body;
}
map $request_uri $cache_request_uri {
default $request_uri;
}
##END HTTP BLOCK
##etc all default Nginx stuff
##INSIDE SERVER BLOCK
# Support Clean (aka Search Engine Friendly) URLs | https://docs.joomla.org/Nginx#Configure_Nginx
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#rewrite_by_lua_block { ##tried this one too also did not work
access_by_lua_block {
local function sort_args(input)
local args_table = input
local args_name = {}
local newargs = {}
for name, value in pairs(args_table) do
if type(value) == "table" then
for k, v in pairs(value) do
table.insert(newargs, name .. "=" .. value[k])
end
else
table.insert(args_name, name) -- maybe you would like incase-sensitive.
end
end
for _, name in ipairs(args_name) do
table.insert(newargs, name .. "=" .. args_table[name])
end
table.sort(newargs) --Sort the table into order
local output = table.concat(newargs, "&")
return output --set the args to be the output
end
--GET requests
--if ngx.HTTP_GET then
local get_uri_args = ngx.req.get_uri_args()
local args_output = sort_args(get_uri_args)
local uri = (ngx.var.uri or "")
local is_args = (ngx.var.is_args or "")
local args = (args_output or "")
--Set the cache URI key
ngx.var.cache_request_uri = string.lower(uri .. is_args .. args) --make all lowercase for a higher cache hit ratio
--ngx.exec(ngx.var.cache_request_uri)
--nulled this out because this caused the following error | rewrite
or internal redirection cycle while internally redirecting to
"/index.php",
--end
--END GET requests
--]]
} #END LUA BLOCK
#etc fastcgi caching settings and key
fastcgi_cache_key "$scheme$host$cache_request_uri$request_method$cache_request_body";
#fastcgi stuff
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi.conf;
} #END PHP BLOCK
##END INSIDE SERVER BLOCK
Now the problem is the following.
I request a URL like this :
/index.php?option=com_details
It works flawlessly and all is great. (direct access to the location PHP block it seems)
If i request the URL for the same page what is a SEF url that goes through "try_files" i get problems.
/details
This will show me the websites homepage for some reason.
Even URL's like this :
/details&help=me
/details&contact=page
All
show the websites homepage i can't figure out how to get it to work I
don't know what to do to get it to work as I intend displaying their
rightful pages instead of the homepage each time, at the same time
running the Lua code set my "cache_request_uri" correctly so my
fastcgi_cache_key matches and has a higher cache HIT ratio.
So the Lua code works great its just fixing the INTERNAL try_files issue now.
Thank's in advance if you can assist me "AGAIN" <3
On Wednesday, 12 July 2017 13:14:18 UTC+1, tokers wrote:
Hello!
Firstly, i must say sorry for my poor engish. -.-!
For the error log you paste:
lua_args_sort.lua:26: attempt to concatenate a nil value
Well, i think you should code more carefully. the keys in args_table is all in lowercase, so when you accessing them, you also need to use the lowercase form.
for _, name in ipairs(args_name) do
table.insert(newargs, name .. "=" .. args_table[name]) -- args_table[string.lower(name)]
end
On Tuesday, July 11, 2017 at 9:02:13 PM UTC+8,
c0nw...@googlemail.com wrote:
Hello again tokers <3 :)
I am having a bit of trouble with the incase sensative thing you mentioned in a nulled / commented out statement. "
-- maybe you would like incase-sensitive.
"
I wanted to make the arguement names lower case. The values can be what user supplied as for the sake of
"?SEARCH=Hello"
"?Search=Hello"
"?SeArCh=Hello"
All should output this :
"?search=Hello"
lua_args_sort.lua:26: attempt to concatenate a nil value
The culprit is this :
table.insert(args_name, string.lower(name)) -- maybe you would like incase-sensitive.
How can I make arg names lower case ?
On Monday, 10 July 2017 09:44:20 UTC+1, tokers wrote:
Hello!
I browsed through your code, and i think the devil is in here
for key, val in pairs(args_table) do
if type(val) == "table" then
--ngx.say(key, ": ", table.concat(val, ", "))
else
--ngx.say(key, ": ", val)
table.insert(args_name, name) -- table.insert(args_name, key)
end
end
On Monday, July 10, 2017 at 3:30:06 PM UTC+8,
c0nw...@googlemail.com wrote:
I eliminated all the errors and the only problem left is there is no output....But I can't see and don't know why :(
location = /test_GET_args {
content_by_lua_block {
local args_table = ngx.req.get_uri_args()
local args_name = {}
for key, val in pairs(args_table) do
if type(val) == "table" then
--ngx.say(key, ": ", table.concat(val, ", "))
else
--ngx.say(key, ": ", val)
table.insert(args_name, name)
end
end
table.sort(args_name)
local newargs = {}
for _, name in ipairs(args_name) do
table.insert(newargs, name .. "=" .. args_table[name])
end
local output = table.concat(newargs, "&")
if output then
ngx.say(" FINISH " .. output .. "")
ngx.var.args = output --set the args to be the output
end
--Check the args order has been optimized
local args_table = ngx.req.get_uri_args()
for key, val in pairs(args_table) do
if type(val) == "table" then
ngx.say(key, ": ", table.concat(val, ", "))
else
ngx.say(key, ": ", val)
end
end
}
}
The ngx.var.args should be the URL supplied but ordered neatly when checked at the end.
But instead it does not output anything...
So this URL :
/test_GET_args?m=hello&a=3&b=42&c=1&z=2&y=4&x=5
Should become this and be confirmed in the output too :
/test_GET_args?a=3&b=42&c=1&m=hello&x=5&y=4&z=2
But all I get in my output is "FINISH"
ngx.say(" FINISH " .. output .. "")
And the following Check should output everything that has been ordered but does not output anything...
--Check the args order has been optimized
local args_table = ngx.req.get_uri_args()
for key, val in pairs(args_table) do
if type(val) == "table" then
ngx.say(key, ": ", table.concat(val, ", "))
else
ngx.say(key, ": ", val)
end
end
I don't know what is wrong because there are no errors anymore...
On Saturday, 8 July 2017 09:25:47 UTC+1, tokers wrote:
Do you know what directive i should use because of the execution order of things some *_lua directives execute before others.
I think you can use the directive rewrite_by_lua_file, because the fastcgi module work on the content phase.
Can you help with the Lua code to modify and orde ngx.var.new_request_uri
I have already said, ngx.var.request_uri is the one from the http request line(raw), it is inconvenient if you want to fetch the args, alternatively, you can get your args table by the method
ngx.req.get_uri_args, then sort these keys(arg_name) using table.sort like the following code(just for demonstration):
local args_table = ngx.req.get_uri_args
local args_name = {}
for name, _ in pairs(args_table) do
table.insert(args_name, name) -- maybe you would like incase-sensitive.
end
table.sort(args_name)
local newargs = {}
for _, name in ipairs(args_name) do
table.insert(newargs, name .. "=" .. args_table[name])
end
ngx.var.args = table.concat(newargs, "&")
Then you construct your ngx.var.new_request_uri by the combination of ngx.var.uri and ngx.var.newargs.