0

I have a laravel server fronting a wordpress hosted on another server. The laravel server is receiving all traffic. I would like to direct specific routes to the local index.php (laravel) and all others to the wordpress. Like this:

/a/* --> laravel server (localhost)
/b/* --> laravel server (localhost)
/* --> wordpress (separate server)

My nginx conf currently has this:

index index.html index.htm index.php;

location ~* /[a|b]/.+ {
  try_files $uri $uri/ /index.php?$query_string;
}

location ^~ / {
  proxy_pass https://10.0.1.44;
  proxy_set_header   Host             $host;
  proxy_set_header   X-Real-IP        $remote_addr;
  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

The wordpress is receiving all routes. How can I force /a/* and /b/* to get served by index.php on the local server?

1 Answers1

2

The problem is location ^~ / directive. This makes the prefix match explicit and prevents nginx from looking at regular expression matches.

Try the following:

location ~*^/[ab] {
     try_files $uri $uri/ /index.php?$query_string;
}

location / {
    proxy_pass https://10.0.1.44;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63