简体   繁体   English

如何使用位置参数重写 NGINX 中的 URL?

[英]How to rewrite URL in NGINX with location parameter?

i have a Application (Openproject) on a Webserver.我在 Web 服务器上有一个应用程序(Openproject)。 this is Reachable under http://10.0.0.1:8000/这是在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在我的用户和 Web 服务器后面是一个 NGinx,我需要在特定 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):所以我在我的 Nginx Configuaion 中进行了以下更改(在这个 NGINX 实例中,多个网站使用“位置”设置发布):

  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.但是当我通过 Reverseproxy 打开页面时,Webbrowser 只显示一个白页。


In the Webbrowser Debugger i see, that some paths are wrong, so the browser couldn´t load it.在 Webbrowser Debugger 中,我看到某些路径是错误的,因此浏览器无法加载它。 Example:例子:

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

Correct would be:正确的应该是:

https://ngrp.com/openproject/assets/frontend/styles.c3a5e7705d6c5db9cfc1.css 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?那么有人可以告诉我,需要哪些配置,以便我可以在 URL https://ngrp.com/openproject/ 下成功打开项目?

Thank you very much.非常感谢。

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 /当您proxy_pass代理整个 HTTP 请求时,这意味着您实际上是在http://10.0.0.1:8000/上请求GET /openproject而不仅仅是GET /

You can add this line before the proxy_pass to fix this and remove the /openproject prefix :您可以在 proxy_pass 之前添加此行以解决此问题并删除/openproject前缀:

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

This changes the requested URL from /openproject/... to /...这会将请求的 URL 从/openproject/...更改为/...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM