How to rewrite URL in NGINX with location parameter?

374 views Asked by At

i have a Application (Openproject) on a Webserver. this is Reachable under http://10.0.0.1:8000/

Behind my users and the Webserver is a NGinx on which i need to publish under a specific URL: https://ngrp.com/openproject

so i made the following changes in my Nginx Configuaion (in this NGINX instance multiple Websites are published with the "location" settings):

  location /openproject/ {
   proxy_pass             http://10.0.0.1:8000/;
   include                /etc/nginx/conf.d/proxy.conf;
 }

But when i open the page through the Reverseproxy, the Webbrowser displays only a White Page.


In the Webbrowser Debugger i see, that some paths are wrong, so the browser couldn“t load it. Example:

https://ngrp.com/assets/frontend/styles.c3a5e7705d6c5db9cfc1.css (/openproject/ is missing in the URL)

Correct would be:

https://ngrp.com/openproject/assets/frontend/styles.c3a5e7705d6c5db9cfc1.css

So can somebody please tell me, which configuration is needed, so i can Openproject under the URL https://ngrp.com/openproject/ successfully?

Thank you very much.

1

There are 1 answers

1
Misfits09 On

When you proxy_pass you proxy the entire HTTP request meaning that you are actually requesting GET /openproject on http://10.0.0.1:8000/ rather than just GET /

You can add this line before the proxy_pass to fix this and remove the /openproject prefix :

rewrite /openproject/(.*) /$1 break;

This changes the requested URL from /openproject/... to /...