Caddy how to determine user-agent proxy to the new host?

nginx like this…

         server {
        listen       80;
        server_name  spa-site.com ;
        location / {
            proxy_set_header  Host            $host:$proxy_port;
            proxy_set_header  X-Real-IP       $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
if ($http_user_agent ~* "Baidu") {
             proxy_pass http://seo.com;
         }   
        root  D:\myWork\pc-vue-web\dist;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;

    }
 location /api {
        proxy_pass api.com;  
    }
}`

caddy,How to achieve it?呢

like this no way

 spa-site.com:80 { 
  root D:\myWork\pc-vue-web\dist
  gzip
  log ../access.log
  ext .html
  proxy /api  api.com
  errors {
        404 /index.html
    }
   rewrite / {
    if {>User-agent} has Phone
     to proxy  seo.com
}
   
}

seo.com:80{
  root D:\seo
  gzip
  log ../access.log

  ext .html
}`

Maybe something like this could work:

rewrite /api {
    if {>User-Agent} has Phone
    to /phone{path}
}

proxy /phone xxx.com {
    transparent
    without /phone
}
1 Like

Thank you, my code has an error… Have corrected…

transparent
without /phone

is unknow directive …

The first line of your Caddyfile is always the site to serve. :wink:

1 Like

Thanks,that >user-agent is not like this Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 ?