Score:0

nginx as reverse proxy for different PHP backends

ru flag

I maintain two Debian Linux servers, A and B. A is rather old and runs a old PHP installation (5.4), while B runs a newer (7.2). Both run Apache as a web server. Server A uses PHP as a module, while server B uses PHP FPM.

What I'd like to do is to have the same domain name for both servers, eg. mydomain.com. When a visitor requests mydomain.com/pathA the response should originate from server A, while requests to mydomain.com/pathB the responses must originate from server B.

I've read that nginx can do this. If there's a third server, eg. C with nginx installed, it could act as a reverse proxy for both servers.

First of all, is what I think possible with nginx? If so, could you please point me to some examples for configuring nginx to work like this?

Thank you.

HBruijn avatar
in flag
The jargon for the configuration you want/need is indeed “reverse proxy” and the associated nginx directive is `proxy_pass`. The manual should be a good start
ru flag
I have this snippet in the code configuration: location /mypath/ { proxy_pass http://myserver/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } It works for resources that reside in the / of myserver, but everything under a suburi (like /css or /images) returns a 404. Apparently the requested url does not get rewritten under the /mypath url. Any ideas?
HBruijn avatar
in flag
That is much clearer and specific question than your original one. Note that you can edit your question rather than (only) adding those details in a comment where almost all formatting gets lost. - You might want to look at this Q&A https://serverfault.com/a/932636/37681
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.