Как я могу установить обратный прокси для такого динамического URL?
htttp://myhost/?url => https://www.google.com
Я пытался пройти, используя arg_url
но его нарушение
server
{
listen 80;
listen [::]:80;
server_name myserver;
# Nginx vs. Lua
#
# Comment: # vs. --
# Concat: NIL vs. ..
# $is_args$args vs. ngx.var.is_args .. ngx.var.args # query string
# $1 vs. ngx.var[1] # regex capturing group 1
# $2 vs. ngx.var[2] # regex capturing group 2
location /
{
set $urlname $arg_url;
rewrite_by_lua_block
{
-- Probs with AJAX/XHR and/or Websockets!
ngx.log(ngx.ALERT, 'See this text in /var/log/nginx/error.log')
local map = {
GET = ngx.HTTP_GET,
POST = ngx.HTTP_POST,
}
ngx.req.read_body()
local res = ngx.location.capture('/location_2' .. (ngx.var.request_uri or ''), {
method = map[ngx.var.request_method],
body = ngx.var.request_body
})
-- Detect/change redirect...
local url = ngx.var.arg_url
local redirect_target = res.header.Location
if redirect_target and res.status > 300 and res.status < 309 then
ngx.log(ngx.ALERT, redirect_target)
local redirect_target_changed, n, err = ngx.re.gsub(redirect_target,url, 'myserver')
ngx.log(ngx.ALERT, redirect_target_changed)
return ngx.redirect(redirect_target_changed, 303)
else
ngx.exec('@named_location_3')
return ngx.exit(ngx.HTTP_OK)
end }
}
location /location_2
{
#resolver 8.8.8.8;
proxy_pass urlname;
}
location @named_location_3
{
#resolver 8.8.8.8;
proxy_pass urlname$request_uri;
}
Аналогично этому вопросу. Скрыть URL-адрес обратного прокси-сервера Nginx