Feb 10, 2025
0
Level 2
Nginx proxy_pass config
I have an API that serves as the backend for a few front-end apps. All of them are hosted from the same server (using forge). The api is hosted at api.example.com and the front-ends are hosted at app1.example.com and app2.example.com.
I'm trying to set up some proxy_passes so that when I navigate to example.com/app1 it will serve up app1.example.com (including any routes and query strings - so example.com/app1/page1 will serve up app1.example.com/page1).
So far I have the following but it's giving me a 502 Bad Gateway error. Does anyone know how to do this (and if it's even possible!)?
location /app1/ {
proxy_pass https://app1.example.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
try_files $uri $uri/ $uri.html /index.php?$query_string;
}
Please or to participate in this conversation.