This has been asked on SO before but the answers have not been generalized. So here goes.
I have two different web apps. They were made to be on different servers at the root. But now they are going to be placed into subdirectories on the same server. The script below is sending the subdirectory along with the URI's to the scripts. This is a problem.
old urls:
new urls:
The store site is seeing /store/items/1
when it wants to just see /items/1
. The same goes for the backoffice site.
My attempt:
location /store {
try_files @store_site;
}
location /backoffice {
try_files @backoffice_site;
}
location @store_site {
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/store_site.sock;
proxy_set_header Host $host;
}
location @backoffice_site {
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/backoffice_site.sock;
proxy_set_header Host $host;
}
Again, the store site is getting URLs with the /store
prefix and backoffice is getting /backoffice
. Those sites were coded to not expect those prefixes. I need to remove the /store
and /backoffice
prefix before sending to the actual site.
Is this a rewrite rule thing?
I tried this based on this SO page and it didn't work. I must not understand something about the syntax.
location /store {
rewrite ^/store/(.*) /$1;
try_files $uri @store_site;
}
Update
Apparently, this works (added break;
) Is this a complete solution?
location /store {
rewrite ^/store/(.*) /$1 break;
try_files $uri @store_site;
}