Redirect requests to another proxy_path based on Header (Nginx example included)

I want make another port to php fastcgi_pass based on some “if” like

upstream http_backend1 {
upstream http_backend2 {

location ~ \.php {
            fastcgi_pass http_backend1;
            if ($http_x_forwarded_proto = "http") {
                fastcgi_pass http_backend2;

It can be possible with Caddy/

Something like this can work. I think rewrite suits this better since the redirection is internal and not exposed to the user.

proxy /http_backend

rewrite {
    if {path} ends_with .php
    if {scheme} is http
    to /http_backend
1 Like

Great! If i want to use jwt token custom claim for variable in {sheme}?

There is no JWT plugin for Caddy yet but you can access any header via {>Header} e.g. {>User-Agent}.

Check the documentation for placeholders to see all supported ones.

Much Thanks)

There’s this one - unless you were talking about something else?


I cant return any variable in this plugin. But can make some restrictions what return true or false. I need get custom claim from token and use that for my conditions of proxy.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.