How to remove a subdirectory from the url before passing to a script? How to remove a subdirectory from the url before passing to a script? nginx nginx

How to remove a subdirectory from the url before passing to a script?


You need to rewrite the uri without triggering a redirection as noted by using break.

Depending on the details of your set up, whether everything should go to the backend or whether Nginx should serve some requests such as static files, you will need either ...

location /store {    try_files $uri @store_site;}location /backoffice {    try_files $uri @backoffice_site;}location @store_site {    rewrite  ^/store/(.*) /$1 break;    include uwsgi_params;    uwsgi_pass unix:/var/run/uwsgi/store_site.sock;}location @backoffice_site {    rewrite  ^/backoffice/(.*) /$1 break;    include uwsgi_params;    uwsgi_pass unix:/var/run/uwsgi/backoffice_site.sock;}

... or

location /store {    rewrite  ^/store/(.*) /$1 break;    include uwsgi_params;    uwsgi_pass unix:/var/run/uwsgi/store_site.sock;}location /backoffice {    rewrite  ^/backoffice/(.*) /$1 break;    include uwsgi_params;    uwsgi_pass unix:/var/run/uwsgi/backoffice_site.sock;}


I suggest you try this for an item:

location /store/ {    rewrite  ^/store/(.*) /$1 break;    include uwsgi_params;    proxy_set_header Host $host;    uwsgi_pass unix:/var/run/uwsgi/store_site.sock;}

Haven't tested it but I think it should work.