Обратный прокси-сервер nginx, затем возвращает статический файл (попробуйте файлы)

Можно ли сделать что-то вроде этого

    location / {
        proxy_pass https://example.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        // Add proxies response headers and serve a static file
        try_files $uri $uri/ =404;
    }

nginx nginx-обратный прокси

dj_boy

1 ответ
1

Ок, я разобрался

    location /rp {
        internal;
        proxy_pass https://example.com/rp.php; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Rp-Ol $scheme://$http_host$request_uri; // get original url
    }

    location / {
        access_by_lua_block {
            local res = ngx.location.capture("/rp")
            ngx.ctx.rp_cookie = res.header["Set-Cookie"]
            return
        }
        
        header_filter_by_lua_block {
            local function merge_cookies(a, b)
                local c = a or b
                if (a and b) == nil then return c end
                if type(c) == "string" then c = {c} end
                if type(b) == "string" then table.insert(c, b) else
                    for _, v in ipairs(b) do table.insert(c, v) end
                end
                return c
            end
            ngx.header["Set-Cookie"] = merge_cookies(ngx.header["Set-Cookie"], ngx.ctx.rp_cookie) 
        }
        

        try_files $uri $uri/ =404;
    }

dj_boy

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *