0

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?

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;
}
  • 1
    If the question is a duplicate - please flag it as such. – AD7six Nov 24 '14 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.