I have an app with a frontend written in Angular on server 1 made accessible in the local network through apache (accessed through ip on port 81: http://192.168.123.123:81).
Now, for various reasons I have to reverse proxy that site using nginx on server 1.
If I make the proxy at "location /" everything works as it should:
listen 80;
server_name example.com;
location / {
proxy_pass http://192.168.123.123:81/;
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;
}
The thing is that I must have the site at example.com/foo, so I simply changed the location:
location /foo/ {
proxy_pass http://192.168.123.123:81/;
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;
}
I doesn't work. By doing this, I get a blank page in the browser and a 404 for every js file. I then read that nginx treats location directives differently when using variables so I searched for solutions. The only thing I found was using a rewrite to remove "foo" from the uri sent the other server:
rewrite ^/foo(.*)$ $1 break;
Again, it doesn't work. I also tried playing with the slashes from the location, rewrite and the proxy_pass url, but without success.
I really don't know what to try anymore. Please bear with me, I'm still a begginner.