Nginx-Proxy-Anfrage an die in der GET-Variable angegebene URL

Nginx-Proxy-Anfrage an die in der GET-Variable angegebene URL

Ich brauche Nginx, um auf eine Anfrage wie diese zu antworten

https://example.org/proxy/?url=https://othersite.com/path/file.php%%a=test123%%b=321tset

oder eine ähnliche Methode, wie

https://example.org/proxy/https://othersite.com/path/file.php?a=test123&b=321tset

durch Weiterleitung der Anfrage an

https://othersite.com/path/file.php?a=test123&b=321tset

Gibt es eine Möglichkeit, dies durch Umschreiben oder eine andere Regel zu tun? Jede Hilfe wäre willkommen. Vielen Dank im Voraus.

Antwort1

Willkommen bei SE. Diese Weiterleitungen können mithilfe von Anweisungen erfolgen ifund ich habe es nicht mit einem Nginx-Proxy versucht.

ifFügen Sie Ihrem Nginx- Block die folgenden Blöcke hinzu server, um sie nach Bedarf umzuleiten

server {
    ...
    ...

    #For https://example.org/proxy/?url=https://othersite.com/path/file.php%%a=test123%%b=321tset

    if ($request_uri ~ ^/proxy/\?url=(.*)$) {
        return 301 $1;
    }

    #For https://example.org/proxy/https://othersite.com/path/file.php?a=test123&b=321tset

    if ($request_uri ~ ^/proxy/(https\:\/\/(.*))$) {
        return 301 $1;
    }
}

Aktualisieren:

Sie können Proxy-Blöcke verwenden location, anstattif

location ~ /proxy/\?url=(.*)$ {
    proxy_pass $1;
    proxy_set_header Host $host;
}

location ~ /proxy/https\:\/\/(.*)$ {
    proxy_pass $1;
    proxy_set_header Host $host;
}

verwandte Informationen