-1

I'm dealing with some legacy issues where I have to reconfigure servers hosting a PHP based application. One of the decisions was to move away from Apache onto Nginx.

Now the application hosts two kinds of responses;

/some/path -> HTML templates
/api/some/path -> JSON

The application is based on Laravel. Now, I have two virtual hosts, my.app.com and api.app.com. What I've thought of as a decent solution is to have api.app.com proxy the requests to my.app.com with a /api prepended to the request path. So;

GET api.app.com/user -> NGINX PROXY -> my.app.com/api/user

I'm no expert at Nginx configuration and this is what I think should work:

location / {
    proxy_pass http://my.app.com:8888/api;
    proxy_set_header X-Real-IP $remote_addr;
}

The idea is to ensure that people trying to GET from api.app.com/something actually get a response from my.app.com/api/something But that doesn't work. I keep getting exceptions from the app saying that the path cannot be found in the routes.

Can anyone tell me what's going on here?

Xavier Lucas
  • 12,815
  • 2
  • 44
  • 50
Ashesh
  • 224
  • 1
  • 13
  • Sounds like [you need a rewrite directive](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass). – AD7six Nov 24 '14 at 16:01

1 Answers1

0

A tip from https://serverfault.com/a/586607:

location ~ /(?<path>.*) {
    proxy_pass http://my.app.com:8888/api/$path;
    proxy_set_header X-Real-IP $remote_addr;
}
NikoNyrh
  • 161
  • 6